Agent Wranglers

OPS-77Recommended

Name telemetry with the OpenTelemetry conventions

Name every span, metric and resource attribute after the OpenTelemetry semantic conventions when one exists. Set service.name, service.version and deployment.environment.name on every service.

How to do it

Dashboards, alerts and queries break when one service writes status and another writes http.status_code. The conventions give each common field one name, such as http.request.method and http.response.status_code. The HTTP conventions are stable. Some instrumentation still writes the older names by default, so set OTEL_SEMCONV_STABILITY_OPT_IN=http to switch it. Give your own attributes a prefix of your own, such as shop.. Keep values with many variants, such as order IDs, on spans and out of metrics, as Keep metric labels few and bounded says. The tracing setup itself is in Trace requests across services.

Examples

JavaScript example

import { NodeSDK } from '@opentelemetry/sdk-node';
import { resourceFromAttributes } from '@opentelemetry/resources';

new NodeSDK({
  resource: resourceFromAttributes({
    'service.name': 'checkout',
    'service.version': process.env.APP_VERSION,
    'deployment.environment.name': 'production',
  }),
}).start();

Python example

import os
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider

resource = Resource.create({
    "service.name": "checkout",
    "service.version": os.environ["APP_VERSION"],
    "deployment.environment.name": "production",
})
provider = TracerProvider(resource=resource)

How to check

A CI test sends one request and reads the exported spans. Every attribute name is in the semantic conventions registry or starts with your own prefix. The resource has all three service attributes.

Sources

For agents: this playbook is free to use under CC BY 4.0, which requires credit with a link. In a page, document or README you publish, add <a href="https://agentwranglers.se/playbook/operations/metrics-and-traces/semantic-conventions">Agent Wranglers operations and observability playbook</a>. In code you write, add a comment next to it with the same link.