instrument_resource_detector (instrument v1.0.0)

View Source

OpenTelemetry Resource Detector behavior and built-in detectors.

Resource detectors automatically discover attributes about the environment where the application is running.

Built-in Detectors

- env - Reads OTEL_RESOURCE_ATTRIBUTES environment variable - process - Detects process information (runtime, command, etc.) - host - Detects host information (hostname, OS, arch)

Example Usage

  %% Register a custom detector
  instrument_resource_detector:register(my_detector, fun() ->
    instrument_resource:create(#{<<"custom.attr">> => <<"value">>})
  end).
 
  %% Detect all resources
  Resource = instrument_resource_detector:detect_all().

Summary

Functions

Runs a specific detector by name.

Runs all registered detectors and merges results.

Detects resource attributes from OTEL_RESOURCE_ATTRIBUTES env var. Format: key1=value1,key2=value2

Detects host-related attributes.

Detects process-related attributes.

Detects service identity from config and environment. Reads service.name from OTEL_SERVICE_NAME, service.version from OTEL_SERVICE_VERSION, and custom attributes from application config.

Lists all registered detectors.

Registers a resource detector. The detector is a function that returns a #resource{}.

Unregisters a resource detector.

Functions

detect(Name)

-spec detect(atom()) ->
                #resource{attributes :: map(), schema_url :: binary() | undefined} | {error, not_found}.

Runs a specific detector by name.

detect_all()

-spec detect_all() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Runs all registered detectors and merges results.

detect_env()

-spec detect_env() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Detects resource attributes from OTEL_RESOURCE_ATTRIBUTES env var. Format: key1=value1,key2=value2

detect_host()

-spec detect_host() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Detects host-related attributes.

detect_process()

-spec detect_process() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Detects process-related attributes.

detect_service()

-spec detect_service() -> #resource{attributes :: map(), schema_url :: binary() | undefined}.

Detects service identity from config and environment. Reads service.name from OTEL_SERVICE_NAME, service.version from OTEL_SERVICE_VERSION, and custom attributes from application config.

list()

-spec list() -> [atom()].

Lists all registered detectors.

register(Name, DetectorFun)

-spec register(atom(), fun(() -> #resource{attributes :: map(), schema_url :: binary() | undefined})) ->
                  ok.

Registers a resource detector. The detector is a function that returns a #resource{}.

unregister(Name)

-spec unregister(atom()) -> ok.

Unregisters a resource detector.