OpenTelemetry Resources in Python

Telemetry data is indexed by service. In OpenTelemetry, services are described by resources, which are set when the OpenTelemetry SDK is initialized during program startup. We want our data to be normalized, so we can compare apples to apples. OpenTelemetry defines a schema for the keys and values which describe common service resources such as hostname, region, version, etc. These standards are called Semantic Conventions, and are defined in the OpenTelemetry Specification.

We recommend that, at minimum, the following resources be applied to every service:

AttributeDescriptionExampleRequired?
service.nameLogical name of the service.
MUST be the same for all instances of horizontally scaled services.
shoppingcartYes
service.versionThe version string of the service API or implementation as defined in Version Attributes.semver:2.0.0No
host.hostnameContains what the hostname command would return on the host machine.server1.mydomain.com,No

Python Configuration

Resources can be set during launcher configuration at program startup.

configure_opentelemetry(
    access_token="my-token",
    service_name="service-123",
    service_version="1.2.3",
    resource_attributes={
      "host.hostname":  socket.gethostname(),
		  "container.name": "my-container-name",
      "cloud.region": "us-central1",    
    }
 }

Semantic Conventions

Standardizing the format of your data is a critical part of using OpenTelemetry. OpenTelemetry provides a schema for describing common resources, so that backends can easily parse and identify relevant information.

It is important to understand these conventions when writing instrumentation, in order to normalize your data and increase its utility. The semantic conventions for resources can be found in the specification.

The following types of resources are currently defined:

The Python constants for these conventions can be found here.