Skip to main content

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 name
  • service.version - Application version
  • service.instance.id - Unique instance identifier
  • host.name - Hostname
  • process.pid - Process ID
  • deployment.environment - Environment (dev, staging, prod)

Resource builders

OpenTelemetry Rust provides two ways to create resources:

Default builder

Includes built-in detectors:
The default builder includes:
  • SdkProvidedResourceDetector - SDK name and version
  • TelemetryResourceDetector - Telemetry SDK information
  • EnvResourceDetector - 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:
Environment variables:
  • OTEL_RESOURCE_ATTRIBUTES - Key-value pairs: key1=value1,key2=value2
  • OTEL_SERVICE_NAME - Service name (overrides service.name in attributes)
Example:

Service name priority

Service name is resolved in this order (highest to lowest priority):
  1. OTEL_SERVICE_NAME environment variable
  2. service.name in OTEL_RESOURCE_ATTRIBUTES
  3. with_service_name() builder method
  4. service.name in custom attributes
  5. Default: "unknown_service"

Custom resource detectors

Implement the ResourceDetector trait:
Use custom detector:

Merging resources

Merge multiple resources together:

Schema URLs

Resources can include a schema URL that identifies the semantic convention version:
When merging resources with different schema URLs, the operation may fail if the schemas are incompatible.

Using resources with providers

TracerProvider

MeterProvider

LoggerProvider

Complete example

OS and Process detectors

For more advanced resource detection (OS, process, host info), use the separate opentelemetry-resource-detectors crate:
This provides:
  • host.name
  • host.arch
  • os.type
  • os.description
  • process.pid
  • process.executable.name
  • process.command_line
  • process.runtime.name
  • process.runtime.version

Best practices

Always set service.name - This is the most important resource attribute for identifying your service in observability backends.
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.

Resources concept

Learn about resource fundamentals

Semantic conventions

Standard attribute names