OpenTelemetry Process Resource Detector

0.3.0 · active · verified Sun Apr 12

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

Install

Imports

Quickstart

Demonstrates how to import and use `ProcessResourceDetector` to gather process-specific attributes and combine them with other resource attributes using `get_aggregated_resources`.

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 ...

view raw JSON →