Skip to main content
Tracing allows you to follow a request or operation through your entire application, creating a hierarchical view of nested operations and their timing.

Understanding Traces

A trace represents a single request or operation flow through your application. It consists of:
  • Trace ID: Unique identifier for the entire trace
  • Root Span: The top-level operation (transaction)
  • Child Spans: Nested operations within the trace

Starting Spans

Automatic Span Finishing

The recommended way to create spans - they finish automatically:

Manual Span Control

For cases where you need explicit control:

Inactive Spans

Create spans that don’t automatically become the active span:
Inactive spans don’t become parent spans for automatic instrumentation. Use them for background tasks or parallel operations.

Working with Active Spans

Setting Active Spans

Control which span is active in a given scope:

No Parent Span

Start a span tree without a parent:

Trace Context

Access trace information from scopes:

Continuing Traces

Continue a trace from incoming headers (useful for distributed tracing):
Use continueTrace to maintain trace context across service boundaries and create a complete distributed trace.

Starting New Traces

Explicitly start a new trace, disconnecting from any parent trace:
Only use startNewTrace when you explicitly want to break the trace chain. In most cases, operations should be part of the ongoing trace.

Span Options

Basic Options

Parent Span Control

Explicitly set the parent span:

Conditional Spans

Only create spans if a parent exists:

Force Transaction

Force a span to be a transaction (root span):

Custom Scope

Provide a specific scope for the span:

Span Attributes

Add structured data to spans:

Semantic Attributes

Use semantic attributes for standard data:

Updating Span Names

Change a span’s name dynamically:

Span Status

Set the status to indicate success or failure:
Span status is automatically set to error if an exception occurs within the span callback.

Span Events

Add timestamped events to spans:

Practical Examples

API Request Handler

Background Job Processing

Best Practices

  1. Use descriptive names: Span names should clearly indicate what operation they represent
  2. Set appropriate operations: Use standard operation types for consistency
  3. Add relevant attributes: Include data that helps identify and debug slow operations
  4. Keep span hierarchies shallow: Deeply nested spans can be hard to analyze
  5. Use semantic attributes: Follow OpenTelemetry conventions for standard data
  6. Finish spans promptly: Don’t leave spans open longer than necessary

Next Steps

Spans

Learn more about individual spans

Distributed Tracing

Track requests across services

Performance

Overview of performance monitoring

Profiling

CPU profiling for performance bottlenecks