Overview
getClient() returns the tracing client instance for manual span operations. Use it to read IDs, update spans, add events, and manage traces.
Signature
Basic Usage
Update Current Span
Record Exceptions
Add Events
Available Client Methods
| Method | Description |
|---|---|
getCurrentTraceId() | Get the current trace ID |
getCurrentSpanId() | Get the current span ID |
updateCurrentSpan() | Update span attributes, status, metadata |
addSpanEvent() | Add a timestamped event to current span |
recordSpanException() | Record an error on current span |
getContextValue() | Get a context value by key |
setContextValue() | Set a context value by key |
isRecording() | Check if tracing is currently active |
getTracer() | Get the underlying OpenTelemetry tracer |
flush() | Manually flush pending spans |
Best Practices
- Use
getClient()within traced functions (workflow, task, agent, tool) - Call client methods only when a span is active
- Add events for significant milestones in your logic
- Record exceptions for better error tracking
- Update spans with custom metadata for filtering and analysis