Overview
A Resource represents the entity producing telemetry data. Resources are immutable and contain attributes that describe your application, service, host, and environment.Resource attributes
Common resource attributes include:service.name- Your service nameservice.version- Application versionservice.instance.id- Unique instance identifierhost.name- Hostnameprocess.pid- Process IDdeployment.environment- Environment (dev, staging, prod)
Resource builders
OpenTelemetry Rust provides two ways to create resources:Default builder
Includes built-in detectors:SdkProvidedResourceDetector- SDK name and versionTelemetryResourceDetector- Telemetry SDK informationEnvResourceDetector- Environment variables
Empty builder
Start with no attributes:Built-in resource detectors
SdkProvidedResourceDetector
Provides OpenTelemetry SDK information:TelemetryResourceDetector
Provides telemetry SDK-specific information:EnvResourceDetector
Detects resources from environment variables:OTEL_RESOURCE_ATTRIBUTES- Key-value pairs:key1=value1,key2=value2OTEL_SERVICE_NAME- Service name (overridesservice.namein attributes)
Service name priority
Service name is resolved in this order (highest to lowest priority):OTEL_SERVICE_NAMEenvironment variableservice.nameinOTEL_RESOURCE_ATTRIBUTESwith_service_name()builder methodservice.namein custom attributes- Default:
"unknown_service"
Custom resource detectors
Implement theResourceDetector trait:
Merging resources
Merge multiple resources together:Schema URLs
Resources can include a schema URL that identifies the semantic convention version:Using resources with providers
TracerProvider
MeterProvider
LoggerProvider
Complete example
OS and Process detectors
For more advanced resource detection (OS, process, host info), use the separateopentelemetry-resource-detectors crate:
host.namehost.archos.typeos.descriptionprocess.pidprocess.executable.nameprocess.command_lineprocess.runtime.nameprocess.runtime.version
Best practices
Use semantic conventions - Follow OpenTelemetry semantic conventions for standard attribute names.
Environment-based configuration - Use
OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES environment variables for deployment-specific configuration.Related
Resources concept
Learn about resource fundamentals
Semantic conventions
Standard attribute names