Overview
getCurrentSpanId() returns the span ID of the currently active span. Useful for detailed logging, debugging, and correlating specific operations.
Signature
Basic Usage
Trace and Span IDs Together
Detailed Logging
Error Context
Return Value
Returns the current span ID as a string, orundefined if no span is active.
Best Practices
- Use span IDs for granular operation tracking
- Include span IDs in detailed logs for precise debugging
- Combine with trace IDs for complete context
- Only call within an active span (workflow, task, agent, or tool)
- Different spans have different IDs, even within the same trace