Resources

A resource represents the entity producing telemetry as resource attributes. For example, an OTP Release producing telemetry that is running in a container on Kubernetes has an OTP Release name, a pod name, a namespace, and possibly a deployment name. All four of these attributes can be included in the resource.

In your observability backend, you can use resource information to better investigate interesting behavior. For example, if your trace or metrics data indicate latency in your system, you can narrow it down to a specific container, pod, or Kubernetes deployment.

Using resource detectors

Resource detectors fetch resource attributes from various sources. The default detectors use the OS environment variable OTEL_RESOURCE_ATTRIBUTES and the opentelemetry OTP application environment variable resource.

The detectors to use is a list of module names and can be configured in the Application configuration:

%% sys.config
{opentelemetry, {resource_detectors, [otel_resource_env_var, otel_resource_app_env]}}
## runtime.exs
config :opentelemetry, resource_detectors: [:otel_resource_env_var, :otel_resource_app_env]

Or through the environment variable OTEL_RESOURCE_DETECTORS:

OTEL_RESOURCE_DETECTORS=otel_resource_env_var,otel_resource_app_env

All resources detectors are protected with a timeout, in milliseconds, after which they return an empty value. This allows for resource detectors to do things like hit the network without potentially hanging the entire program indefinitely. The default is 5000 milliseconds and can be set with environment variable OTEL_RESOURCE_DETECTOR_TIMEOUT or Application variable otel_resource_detector_timeout.

Adding resources with OS and OTP application environment variables

With the two default resource detectors enabled you can set resource attributes either with the OS environment variable OTEL_RESOURCE_ATTRIBUTES:

OTEL_RESOURCE_ATTRIBUTES="deployment.environment=development"

Alternatively, use the resource OTP application environment under the opentelemetry Application configuration of sys.config or runtime.exs:

%% sys.config
{opentelemetry, {resource, #{deployment => #{environment => <<"development">>}}}}
## runtime.exs
config :opentelemetry, resource: %{deployment: %{environment: "development" }}

Resource attributes in the resource OTP application environment variable are flattened and combined with ., so #{deployment => #{environment => <<"development">> } is the same as #{'deployment.environment' => <<"development">>}.

Custom resource detectors

Custom resource detectors can be created by implementing the otel_resource_detector behaviour which contains a single callback get_resource/1 that returns an otel_resource.

Note that there are semantic conventions defined for resource that should be followed if they apply when adding new resource attributes.