Span Basics
A span contains:- Span ID: Unique identifier for the span
- Trace ID: Identifier linking it to a trace
- Parent Span ID: Links to parent span (if any)
- Operation: Type of operation (e.g.,
db.query,http.client) - Description/Name: What the span measures
- Start/End Time: When the span began and ended
- Status: Success or failure indicator
- Attributes: Custom key-value data
Creating Spans
Auto-finishing Spans
Spans that finish when the callback completes:Manual Span Control
Control span lifetime explicitly:Async Operations
Spans work seamlessly with async/await:Span Hierarchy
Parent-Child Relationships
Spans automatically form a hierarchy:Root Spans (Transactions)
The top-level span in a trace is called a transaction:Transactions are sent to Sentry when the root span finishes. Child spans are included in the transaction.
Span Attributes
Setting Attributes
Add custom data to spans:Removing Attributes
Standard Attributes
Use semantic attributes for common data:Span Status
Indicate whether a span succeeded or failed:Status Codes
SPAN_STATUS_UNSET(0): Default, no status setSPAN_STATUS_OK(1): Operation completed successfullySPAN_STATUS_ERROR(2): Operation failed
HTTP Status Codes
Automatically set status from HTTP responses:Span Events
Add timestamped events within a span:Updating Span Names
Change span names dynamically:Span Context
Access span identifiers:Span Sampling
Control whether a span is recorded:Getting Span Data
Retrieve span information:Span Links
Link spans to other traces:Span links allow you to connect spans across different traces, useful for batch processing or fan-out operations.
Practical Examples
Database Query
HTTP Request
File Processing
Caching Operation
Span Best Practices
- Use descriptive names: Clearly indicate what the span measures
- Set appropriate operations: Use standard operation types
- Add relevant attributes: Include data that helps identify slow operations
- Set status correctly: Indicate success or failure
- Keep spans focused: Each span should represent one logical operation
- Don’t create too many spans: Balance detail with overhead
- Finish spans promptly: Don’t leave spans open
Span Limits
Be aware of limits:- Maximum 1000 spans per transaction
- Attribute values are truncated if too large
- Deeply nested spans may impact performance
Next Steps
Tracing
Learn about traces and span relationships
Distributed Tracing
Track spans across services
Performance
Performance monitoring overview
Profiling
CPU profiling for code-level insights