Resources

Você está visualizando a versão em versão em inglês desta página porque ela ainda não foi traduzida. Possui interesse em ajudar? Veja como contribuir.

Um recurso representa a entidade que está gerando telemetria como atributos do recurso. Por exemplo, an OTP Release que está gerando telemetria e que está sendo executado em um container no Kubernetes tem o nome de an OTP Release, um nome de pod, um namespace e possivelmente um nome de deployment. Todos esses quatro atributos podem ser incluídos em um recurso.

No seu backend de observabilidade, você pode usar as informações de um recurso para refinar a investigação de comportamentos relevantes. Por exemplo, se seus dados de rastros ou métricas indicarem latência no seu sistema, você pode restringir a investigação para um determinado container, pod ou deployment do Kubernetes.

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.