Resources

Estás viendo la versión en inglés de está página porque aún no ha sido traducida. ¿Te interesa ayudar? Mira en Contribuir.

Un recurso representa la entidad que produce telemetría como atributos de recurso. Por ejemplo, an OTP Release que produce telemetría y que se está ejecutando en un contenedor en Kubernetes tiene un nombre de an OTP Release, un nombre de pod, un namespace y, posiblemente, un nombre de despliegue. Los cuatro atributos pueden incluirse en el recurso.

En tu backend de observabilidad, puedes usar la información del recurso para investigar mejor un comportamiento interesante. Por ejemplo, si tus datos de trazas o métricas indican latencia en tu sistema, puedes reducirla a un contenedor, pod o despliegue de Kubernetes específico.

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.


Última modificación July 10, 2024: [Erlang] Review propagation docs (#4801) (a7768c5c)