instrument_resource_detector (instrument v1.0.0)
View SourceOpenTelemetry 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
-spec detect(atom()) -> #resource{attributes :: map(), schema_url :: binary() | undefined} | {error, not_found}.
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.
-spec list() -> [atom()].
Lists all registered detectors.
-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{}.
-spec unregister(atom()) -> ok.
Unregisters a resource detector.