Immutable representation of the entity producing telemetry
(resource/sdk.md §"SDK").
A Resource is a set of key-value attributes describing the service (e.g., service.name, host.name) and an optional Schema URL. Resources are associated with TracerProvider/MeterProvider at creation time.
Environment-derived defaults
default/0 reads two environment variables per spec
resource/sdk.md L172-L193 and merges their attributes
on top of the SDK-provided base
(telemetry.sdk.{name,language,version}):
OTEL_RESOURCE_ATTRIBUTES(L179-L189) — comma- separatedkey=valuepairs.,and=characters in keys / values MUST be percent-encoded; we decode viaOtel.API.Baggage.Percent.decode/1(RFC 3986 §2.1). On any malformed pair the entire variable value is discarded per L191-L193 SHOULD.OTEL_SERVICE_NAME(configuration/sdk-environment-variables.mdL116) — populatesservice.name. Takes precedence overservice.namefromOTEL_RESOURCE_ATTRIBUTESwhen both are present. When neither is set the spec semantic-convention fallback"unknown_service"is used.
References
- OTel Resource SDK:
opentelemetry-specification/specification/resource/sdk.md - OTLP proto Resource:
opentelemetry-proto/opentelemetry/proto/resource/v1/resource.proto - OTel SDK env vars:
opentelemetry-specification/specification/configuration/sdk-environment-variables.mdL116
Summary
Functions
Creates a new Resource from attributes and optional schema_url.
Returns the SDK-provided default Resource.
Merges two Resources.
Types
@type primitive_any() :: primitive() | [primitive_any()] | %{required(String.t()) => primitive_any()}
@type t() :: %Otel.SDK.Resource{ attributes: %{required(String.t()) => primitive_any()}, schema_url: String.t() }
Functions
@spec create( attributes :: %{required(String.t()) => term()} | [{String.t(), term()}], schema_url :: String.t() ) :: t()
Creates a new Resource from attributes and optional schema_url.
@spec default() :: t()
Returns the SDK-provided default Resource.
Includes telemetry.sdk.* attributes plus environment-derived
attributes from OTEL_RESOURCE_ATTRIBUTES and OTEL_SERVICE_NAME
(see module doc ## Environment-derived defaults). When
service.name is supplied by neither environment variable, the
spec semantic-convention fallback "unknown_service" is used.
Merges two Resources.
The updating resource's attribute values take precedence when keys
overlap. Schema URL rules:
- If old has empty schema_url → use updating's
- If updating has empty schema_url → use old's
- If both match → use that URL
- If both differ → empty (merge conflict)