Use spans to measure the timing of specific operations within a transaction. Each span represents a unit of work such as a database query, HTTP call, or custom processing.
Required Imports
copy
using Atatus;
using Atatus.Api;
1. StartSpan
Use StartSpan() to create a custom span. You must call End() to complete the span.
Syntax
ISpan span = transaction.StartSpan(name, type, subtype, action);
Parameter
| Parameter | Type | Description |
|---|---|---|
| name | String (Required) | Span name. |
| type | String (Required) | Span type. Use ApiConstants.TypeApp for application operations. |
| subtype | String (Optional) | Span subtype. Use ApiConstants.SubTypeInternal for internal operations. |
| action | String (Optional) | Span action. Use ApiConstants.ActionExec for execution operations. |
Example
copy
using Atatus;
using Atatus.Api;
var transaction = Atatus.Agent.Tracer.CurrentTransaction;
ISpan span = transaction.StartSpan("CheckSubsystems", ApiConstants.TypeApp, ApiConstants.SubTypeInternal, ApiConstants.ActionExec);
try
{
// Your code here
}
catch (Exception ex)
{
span.CaptureException(ex);
}
finally
{
span.End();
}
2. CaptureSpan
Use CaptureSpan() to create a span with automatic lifecycle management. The span ends automatically when the callback completes.
Syntax
transaction.CaptureSpan(name, type, action, subtype, actionType);
Parameter
| Parameter | Type | Description |
|---|---|---|
| name | String (Required) | Span name. |
| type | String (Required) | Span type. |
| callback | callback (Required) | Callback function that receives the span instance. |
| subtype | String (Optional) | Span subtype. |
| actionType | String (Optional) | Span action type. |
Example
copy
using Atatus;
using Atatus.Api;
var transaction = Atatus.Agent.Tracer.CurrentTransaction;
transaction.CaptureSpan("VerifyConfigurations", ApiConstants.TypeApp, (s) =>
{
// Your code here
}, ApiConstants.SubTypeInternal, ApiConstants.ActionExec);
3. CurrentSpan
Use CurrentSpan to access the active span within the current execution context.
Syntax
var span = Atatus.Agent.Tracer.CurrentSpan;
Example
copy
using Atatus;
using Atatus.Api;
var currentSpan = Atatus.Agent.Tracer.CurrentSpan;
if (currentSpan != null)
{
// Access current span properties
}
+1-415-800-4104