Section 7 · Add metrics and traces

The SDK emits spans and metrics but does not create the providers. In Milestone 7 you add a TracerProvider and a MeterProvider to your sample, above the line that constructs the client.

Estimated time: 1 min

Where the providers go in your sample

A TracerProvider and a MeterProvider are OpenTelemetry SDK objects your application creates. The Agent Observability SDK records its spans and metrics through them, and they pass that data to an exporter, which sends it over OTLP. The Agent Observability SDK does not create the providers.

Inside your application, the Agent Observability SDK emits OpenTelemetry spans and metrics internally. Your application's TracerProvider and MeterProvider export the spans and metrics over OTLP to the OTLP endpoint. Generation data goes directly to the Agent Observability API.

The two providers

Your sample constructs the Agent Observability client, captures a generation, and calls client.shutdown(). In Milestone 7 you edit that same file: you add a TracerProvider and a MeterProvider above the line that constructs the client, shut them down after client.shutdown(), and rerun the sample.

Warning

The position in the file matters. If the providers are created after the client, traces and metrics are silently lost.

The SDK configuration page has the snippet for each supported language. The Python snippet adds:

  • A TracerProvider with an OTLP span exporter.
  • A MeterProvider with an OTLP metric exporter.
  • One resource for both providers, Resource.create({"service.name": "my-agent"}), which carries one named value, the service.name attribute set to my-agent.

The snippet shuts down the providers after client.shutdown().

What the OpenTelemetry SDK reads from the environment

Set the OTLP endpoint and any auth headers through environment variables. The OpenTelemetry SDK exporters read them automatically. Generation data goes directly to the Agent Observability API.