Skip to content

Tracing

LucasZF edited this page Sep 8, 2020 · 3 revisions

Official Docs: https://docs.sentry.io/performance-monitoring/getting-started/

.NetCore Configuration.

If you plan to use ContribSentrySdk on a server application running .NetCore you should Include the ContribSentry.AspNetCore in your project and instead of adding the ContribSentrySdkIntegration integration, you should add the ContribSentryNetCoreSdkIntegration integration, the remaining of the ContribSentryOptions are the same compared to the normal ContribSentry options.

Configuration

There are a few configurations that you can set on ContribSentryOptions, those are:

  • RegisterTracingBreadcrumb: if enabled (by default it's true), it'll add a transaction breadcrumb to SentryEvents when the transaction is finished.
  • TracesSampleRate: The chance of sending the transaction, where 1.0 (the default) is always and 0 is never send.

Usage

You can start/finish a Transaction by creating an transaction Object or by 'using'

var transaction = ContribSentrySdk.StartTransaction( name );// return a new transaction.
var child = transaction.StartChild( name );// return a new child
... code to be measured
child.Finish();// finishes the child
// You can add as many childs as you wish on a transaction
transaction.Finish();// finishes and sends the transaction
using(var transaction = ContribSentrySdk.StartTransaction( name ))
{
 var child = transaction.StartChild( name );// return a new child
 ... code to be measured
 child.Finish();// finishes the child
 // You can add as many childs as you wish on a transaction
}

You can also start a child anywhere in the code, as long as there's an active Isolated Transaction, else the child will be discarted

using(var child = SentryTracingSDK.StartChild( url, Post ))
{
... your http request here
 child.Finish(httpstatuscode);// child finished with the current status code
}

Starting a transaction child from the SDK.

AspNetCore

you don't need to run any fancy code to find the correct transaction, simply call ContribSentrySdk.StartChild and the SDK will do the rest.

using(var child = SentryTracingSDK.StartChild( url, Post ))
{
 // your code here
...
 using(var child = ContribSentrySdk.StartChild( url, post)){
  // your request here
  child.Finish(httpstatuscode);// child finished with the current status code
 }
}

Others

You'll need to run the following code to isolate a Transaction if you would like to start a child by not referencing the Tracing object.

var transaction = SentryTracingSDK.StartTransaction( name );
await transaction.IsolateTracking(async ()=>{
 // your code here
...
 using(var child = ContribSentrySdk.StartChild( url, post)){
 // your request here
  child.Finish(httpstatuscode);// child finished with the current status code
  }
});
transaction.Finish();
Clone this wiki locally