MyObservability

Manual Instrumentation

To facilitate the instrumentation of applications even more, you can manually instrument your applications by coding against the OpenTelemetry APIs.

To apply a more granular configuration to the already existing agent you can use the opentelemetry-instrumentation-annotations library.

Also some language do not support auto instrumentation.

Steps:

  1. Import the OpenTelemetry API and SDK
  2. Configure the OpenTelemetry API
  3. Configure the OpenTelemetry SDK
  4. Create Telemetry Data
  5. Export Data

Manual Instrumentation - Tracing

Big Picture: OpenTelemetry Tracing Pipeline

  1. OpenTelemetry Tracing API
  2. OpenTelemetry SDK
    • Telemetry Generation
      • TraceProvider
      • Tracer
    • Tracing Pipeline
      • SpanProcessor
      • SpanExporter

OpenTelemetry Tracing API

The API is what you use in your code to generate trace data. It’s just interfaces (no logic) that define how you:

Ex:

Tracer tracer = GlobalOpenTelemetry.getTracer("my-app");

Span span = tracer.spanBuilder("fetchData").startSpan();
try (Scope scope = span.makeCurrent()) {
    // business logic
    span.setAttribute("user.id", "123");
} finally {
    span.end();
}

OpenTelemetry SDK

The SDK is the actual implementation of the API. It provides the logic to:

You typically bring in this SDK in your app as a dependency.

Ex:

<dependency>
  <groupId>io.opentelemetry</groupId>
  <artifactId>opentelemetry-sdk</artifactId>
  <version>1.34.1</version>
</dependency>

Next Chapter: Sampling

Main Page: Click Here