Resources

You are viewing the English version of this page because it has not yet been fully translated. Interested in helping out? See Contributing.

リソースは、リソース属性としてテレメトリーを生成するエンティティを表します。 たとえば、Kubernetes上のコンテナで実行されているテレメトリーを生成するan OTP Releaseは、an OTP Release名、ポッド名、ネームスペース、および場合によってはデプロイメント名を持ちます。 これらの4つの属性すべてをリソースに含まれることができます。

オブザーバビリティバックエンドでは、リソース情報を使用して興味深い動作をより詳細に調査できます。 たとえば、トレースまたはメトリクスデータがシステムのレイテンシーを示している場合、それを特定のコンテナ、ポッド、または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.