Graham Dumpleton: OpenTelemetr... Note

Graham Dumpleton: OpenTelemetry export in wrapture

Wrapture now integrates OpenTelemetry as a first-class destination for tracing data. The wrapture.otel subpackage, included with every installation, enables seamless export to tracing backends. By adding an [otel] table to the configuration, users can enable tracing, specify a service name, and tune individual signal settings. This configuration allows for detailed introspection into application behavior, including errors and request details.OpenTelemetry environment variables dictate where tracing data is sent, with console exporters available for immediate debugging. Each application event is translated into a span, forming a hierarchical trace. For instance, a Flask request becomes a server span, with internal calls creating nested spans. Error conditions, like a KeyError, are accurately captured with status codes and exception details.The instrumentation automatically captures arguments and other annotated data as span attributes, with sensitive information like credit card numbers being redacted. This ensures that errors are fully documented, appearing on both the specific operation and the parent request span. Distributed tracing across multiple processes is achieved through W3C trace context propagation.Wrapture injects trace context headers into outgoing requests, which are then parsed by the receiving service's middleware. This allows traces to span across different services, maintaining a consistent trace ID. Even when OpenTelemetry export is enabled, wrapture preserves its own minted trace IDs, ensuring continuity.Metrics are also generated from the same traced events, providing aggregated insights without requiring explicit instrumentation code changes. Request durations and call durations are automatically collected and attributed by relevant information like HTTP methods, routes, and status codes. These metrics offer valuable performance and error rate information.The overhead of using wrapture with OpenTelemetry is comparable to direct OpenTelemetry SDK usage. Wrapture optimizes span processing by building finished spans directly, bypassing some of the SDK's internal overhead. This results in lower costs, especially for operations that raise exceptions.The core principle behind wrapture's design remains consistent: correctly observing real-time calls for both testing and production tracing. Whether feeding a testing tape or a tracing backend, the underlying mechanism remains the same. The OpenTelemetry export page provides further details on advanced features like sampling and log signal integration.