traced()
function wraps any function with OpenTelemetry tracing to automatically track its execution. It creates a span for each function call, records input arguments and return values, and captures any exceptions that occur during execution.
The Gentrace SDK automatically configures OpenTelemetry when you
call
init()
. If you have an existing OpenTelemetry setup or need
custom configuration, see the manual setup
guide.Basic usage
GentraceSpanProcessor
when you call init()
, which simplifies the process of converting baggage values to span attributes, ensuring proper trace routing to Gentrace. For manual configuration details, see the OpenTelemetry setup guide.
Overview
Thetraced()
function provides automatic instrumentation for any function in your codebase. It:
- Creates OpenTelemetry spans for each function execution with customizable names
- Records function arguments as span events for debugging and analysis
- Captures return values as span events to track function outputs
- Handles errors automatically by recording exceptions and setting appropriate span status
- Supports both sync and async functions with proper typing preservation
- Allows custom attributes to be attached to spans for enhanced observability