Skip to main content
The 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

The Gentrace SDK automatically configures the 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

The traced() function provides automatic instrumentation for any function in your codebase. It:
  1. Creates OpenTelemetry spans for each function execution with customizable names
  2. Records function arguments as span events for debugging and analysis
  3. Captures return values as span events to track function outputs
  4. Handles errors automatically by recording exceptions and setting appropriate span status
  5. Supports both sync and async functions with proper typing preservation
  6. Allows custom attributes to be attached to spans for enhanced observability

Parameters