Skip to main content

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 service
  • service.version - The version of your service
  • deployment.environment - The environment (production, staging, etc.)
  • k8s.pod.name - The Kubernetes pod name
  • k8s.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 call Resource::builder(), these detectors are automatically included:
  1. SdkProvidedResourceDetector - Provides required SDK attributes
  2. TelemetryResourceDetector - Adds telemetry SDK information
  3. EnvResourceDetector - Reads from environment variables

Environment Variables

The EnvResourceDetector 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

The opentelemetry-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

The service.name attribute is required by the OpenTelemetry specification. The SDK determines it using this priority:
  1. OTEL_SERVICE_NAME environment variable
  2. service.name in OTEL_RESOURCE_ATTRIBUTES
  3. unknown_service:<executable_name> (fallback)
Always set a meaningful service name to identify your service in observability backends.

Using Resources

With Tracer Provider

With Meter Provider

With Logger Provider

Merging Resources

Resources can be merged to combine attributes from multiple sources:
When merging, attributes from the second resource (parameter) override those from the first resource (caller).

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:
  1. If both have the same schema URL, it’s preserved
  2. If both have different schema URLs, the result has no schema URL
  3. 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 service
  • service.namespace - Namespace for service grouping
  • service.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

Always set a service name: This is the most important resource attribute for identifying your service in observability backends.
Use environment variables in production: Configure resources via OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES for flexibility.
Include version information: Add service.version to track which version of your service is running.
Leverage detectors: Use resource detectors to automatically capture environmental information instead of manually configuring it.

Next Steps

Context Propagation

Learn how context flows across services

Signals

Understand traces, metrics, and logs