OpenTelemetry Process Resource Detector
This OpenTelemetry package populates Resource attributes from the running process. It detects process-related information such as PID, executable name, command line, and runtime details, which are then attached to telemetry data for better context and filtering. The current version is 0.3.0, and releases appear to be ad-hoc, following updates in the broader OpenTelemetry Python ecosystem.
Warnings
- breaking Python version requirement changed. Version 0.3.0 and later require Python >=3.8. Previous versions (e.g., 0.2.0) supported Python >=3.6.
- gotcha When manually constructing `Resource` objects or using `get_aggregated_resources`, you must explicitly include `ProcessResourceDetector()` in the list of detectors to ensure process attributes are collected. It is not automatically added if you provide your own list.
- gotcha OpenTelemetry Semantic Conventions, which define attribute names (e.g., `process.pid`, `process.executable.name`), can evolve. While this detector provides these attributes, their precise names or expected values might change with future OpenTelemetry specification updates.
Install
-
pip install opentelemetry-resourcedetector-process
Imports
- ProcessResourceDetector
from opentelemetry_resourcedetector_process import ProcessResourceDetector
- get_aggregated_resources
from opentelemetry.sdk.resources import get_aggregated_resources
Quickstart
from opentelemetry.sdk.resources import get_aggregated_resources
from opentelemetry_resourcedetector_process import ProcessResourceDetector
# Instantiate the process resource detector
process_detector = ProcessResourceDetector()
# Aggregate resources, including the process detector
# Note: The OpenTelemetry SDK often includes built-in detectors by default,
# but if you are manually creating an aggregated resource, you must explicitly
# list all desired detectors.
resource = get_aggregated_resources([
process_detector,
# Add other detectors here if needed, e.g., HostResourceDetector()
])
print("Detected Process Resource Attributes:")
for key, value in resource.attributes.items():
print(f" {key}: {value}")
# In a real OpenTelemetry setup, this 'resource' object would be passed
# to a TracerProvider, MeterProvider, or LoggerProvider.
# Example (conceptual):
# from opentelemetry.sdk.trace import TracerProvider
# tracer_provider = TracerProvider(resource=resource)
# # ... further setup ...