Overview
A Resource is an immutable representation of the entity producing telemetry. It captures information about your application, service, or infrastructure component as a set of attributes. For example, a process running in a Kubernetes pod might have these resource attributes:service.name- The name of your serviceservice.version- The version of your servicedeployment.environment- The environment (production, staging, etc.)k8s.pod.name- The Kubernetes pod namek8s.namespace.name- The Kubernetes namespace
Creating Resources
Using the Builder
The recommended way to create a resource is using the builder pattern:Empty Resources
You can also start with an empty resource:Resource Detectors
Resource detectors automatically discover information about your runtime environment. OpenTelemetry provides several built-in detectors:Default Detectors
When you callResource::builder(), these detectors are automatically included:
- SdkProvidedResourceDetector - Provides required SDK attributes
- TelemetryResourceDetector - Adds telemetry SDK information
- EnvResourceDetector - Reads from environment variables
Environment Variables
TheEnvResourceDetector reads from standard OpenTelemetry environment variables:
The
OTEL_SERVICE_NAME environment variable takes priority over service.name in OTEL_RESOURCE_ATTRIBUTES.Custom Detectors
You can implement custom resource detectors:Additional Detectors
Theopentelemetry-resource-detectors crate provides detectors for:
- Operating System - OS type, version, and architecture
- Process - Process ID, executable name, command line args
- Host - Hostname and other host information
Service Name
Theservice.name attribute is required by the OpenTelemetry specification. The SDK determines it using this priority:
OTEL_SERVICE_NAMEenvironment variableservice.nameinOTEL_RESOURCE_ATTRIBUTESunknown_service:<executable_name>(fallback)
Using Resources
With Tracer Provider
With Meter Provider
With Logger Provider
Merging Resources
Resources can be merged to combine attributes from multiple sources:Schema URL
Resources can have an associated schema URL that defines the semantic conventions being used:Schema URL Merging Rules
When merging resources with schema URLs:- If both have the same schema URL, it’s preserved
- If both have different schema URLs, the result has no schema URL
- If one has a schema URL and the other doesn’t, the existing schema URL is used
Accessing Resource Attributes
Standard Resource Attributes
OpenTelemetry defines semantic conventions for common resource attributes:Service Attributes
service.name- Logical name of the service (required)service.version- Version of the serviceservice.namespace- Namespace for service groupingservice.instance.id- Unique identifier for the service instance
Deployment Attributes
deployment.environment- Environment (production, staging, development)deployment.name- Name of the deployment
Telemetry SDK Attributes
telemetry.sdk.name- Name of the SDK (automatically set)telemetry.sdk.language- Language of the SDK (automatically set to “rust”)telemetry.sdk.version- Version of the SDK (automatically set)
Example
Complete Example
Here’s a complete example showing resource configuration:Best Practices
Next Steps
Context Propagation
Learn how context flows across services
Signals
Understand traces, metrics, and logs