Direct Instrumentation
Direct instrumentation involves manually adding code to your application to generate telemetry data. This requires developers to use the OpenTelemetry SDK specific to their programming language, explicitly invoking functions to create traces, metrics, or logs.- Example Use Case: You might define spans that wrap critical sections of code to monitor database queries or key service calls.
- Advantages:
- Precise Control: Developers control which parts of the application generate telemetry data.
- Contextual Richness: Since code is written by hand, you can include detailed metadata relevant to your business logic.
- Customization: Allows for intricate tracking of custom events, metrics, and logs that fit your specific needs.
Auto-Instrumentation
Auto-instrumentation eliminates the need for manual code changes by injecting telemetry at runtime. This is often achieved through agents or middleware that modify existing code dynamically. For example, Java or Python applications can use agents to hook into libraries and frameworks they rely on.- Example Use Case: A web server library automatically generates spans for HTTP requests without developer involvement.
-
Advantages:
- Fast Setup: No changes to the codebase are required, making it easy to get started.
- Coverage for Standard Libraries: Many popular libraries and frameworks come with built-in support for auto-instrumentation.
- Consistency: Ensures consistent telemetry for common operations, reducing the risk of missing critical observability data.
When to Use Each
- Direct instrumentation is ideal for teams seeking maximum flexibility, particularly for custom workflows or applications with unique behavior.
- Auto-instrumentation is better suited for scenarios where rapid observability is needed, or when standard libraries provide sufficient coverage.