Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
5c26f00
config: add resource and propagator creation from declarative config
MikeGoldsmith Mar 13, 2026
8232012
update changelog with PR number
MikeGoldsmith Mar 13, 2026
8329ae4
fix pylint, pyright and ruff errors in resource/propagator config
MikeGoldsmith Mar 13, 2026
506d816
address review feedback: use _DEFAULT_RESOURCE, fix bool_array coercion
MikeGoldsmith Mar 16, 2026
8232d48
fix linter
MikeGoldsmith Mar 16, 2026
6ed3425
Merge branch 'main' of github.com:open-telemetry/opentelemetry-python…
MikeGoldsmith Mar 16, 2026
99753f9
address review feedback: single coercion table, simplify attributes m…
MikeGoldsmith Mar 16, 2026
8ba91d8
use Callable type annotation on _array helper
MikeGoldsmith Mar 17, 2026
516aecc
Merge remote-tracking branch 'upstream/main' into mike/config-resourc…
MikeGoldsmith Mar 20, 2026
9cfdcce
add detection infrastructure foundations for resource detectors
MikeGoldsmith Mar 20, 2026
103ff08
move service.name default into base resource
MikeGoldsmith Mar 20, 2026
7f51034
remove unused logging import from _propagator.py
MikeGoldsmith Mar 20, 2026
be4baf9
wire process resource detector in declarative config
MikeGoldsmith Mar 20, 2026
aaf29ef
add changelog entry for process resource detector (#5001)
MikeGoldsmith Mar 20, 2026
ac20dfa
merge upstream/main and fix pylint no-self-use in TestProcessResource…
MikeGoldsmith Mar 29, 2026
14d9092
merge upstream/main
MikeGoldsmith Apr 1, 2026
1218462
Merge branch 'main' into mike/config-resource-detector-process
aabmass Apr 2, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

- `opentelemetry-sdk`: Add `process` resource detector support to declarative file configuration via `detection_development.detectors[].process`
([#5001](https://github.com/open-telemetry/opentelemetry-python/pull/5001))
- `opentelemetry-sdk`: Add shared `_parse_headers` helper for declarative config OTLP exporters
([#5021](https://github.com/open-telemetry/opentelemetry-python/pull/5021))
- `opentelemetry-api`: Replace a broad exception in attribute cleaning tests to satisfy pylint in the `lint-opentelemetry-api` CI job
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from opentelemetry.sdk.resources import (
_DEFAULT_RESOURCE,
SERVICE_NAME,
ProcessResourceDetector,
Resource,
)

Expand Down Expand Up @@ -149,6 +150,8 @@ def _run_detectors(
is updated in-place; later detectors overwrite earlier ones for the
same key.
"""
if detector_config.process is not None:
detected_attrs.update(ProcessResourceDetector().detect().attributes)


def _filter_attributes(
Expand Down
72 changes: 72 additions & 0 deletions opentelemetry-sdk/tests/_configuration/test_resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,21 @@
# limitations under the License.

import os
import sys
import unittest
from unittest.mock import patch

from opentelemetry.sdk._configuration._resource import create_resource
from opentelemetry.sdk._configuration.models import (
AttributeNameValue,
AttributeType,
ExperimentalResourceDetection,
ExperimentalResourceDetector,
)
from opentelemetry.sdk._configuration.models import Resource as ResourceConfig
from opentelemetry.sdk.resources import (
PROCESS_PID,
PROCESS_RUNTIME_NAME,
SERVICE_NAME,
TELEMETRY_SDK_LANGUAGE,
TELEMETRY_SDK_NAME,
Expand Down Expand Up @@ -295,3 +300,70 @@ def test_attributes_list_invalid_pair_skipped(self):
self.assertEqual(resource.attributes["foo"], "bar")
self.assertNotIn("no-equals", resource.attributes)
self.assertTrue(any("no-equals" in msg for msg in cm.output))


class TestProcessResourceDetector(unittest.TestCase):
@staticmethod
def _config_with_process() -> ResourceConfig:
return ResourceConfig(
detection_development=ExperimentalResourceDetection(
detectors=[ExperimentalResourceDetector(process={})]
)
)

def test_process_detector_adds_process_attributes(self):
resource = create_resource(self._config_with_process())
self.assertIn(PROCESS_PID, resource.attributes)
self.assertEqual(resource.attributes[PROCESS_PID], os.getpid())
self.assertEqual(
resource.attributes[PROCESS_RUNTIME_NAME],
sys.implementation.name,
)

def test_process_detector_also_includes_sdk_defaults(self):
resource = create_resource(self._config_with_process())
self.assertEqual(resource.attributes[TELEMETRY_SDK_LANGUAGE], "python")
self.assertIn(TELEMETRY_SDK_VERSION, resource.attributes)

def test_process_detector_not_run_when_absent(self):
resource = create_resource(ResourceConfig())
self.assertNotIn(PROCESS_PID, resource.attributes)

def test_process_detector_not_run_when_detection_development_is_none(self):
resource = create_resource(ResourceConfig(detection_development=None))
self.assertNotIn(PROCESS_PID, resource.attributes)

def test_process_detector_not_run_when_detectors_list_empty(self):
config = ResourceConfig(
detection_development=ExperimentalResourceDetection(detectors=[])
)
resource = create_resource(config)
self.assertNotIn(PROCESS_PID, resource.attributes)

def test_explicit_attributes_override_process_detector(self):
"""Config attributes win over detector-provided values."""
config = ResourceConfig(
attributes=[
AttributeNameValue(
name="process.pid", value=99999, type=AttributeType.int
)
],
detection_development=ExperimentalResourceDetection(
detectors=[ExperimentalResourceDetector(process={})]
),
)
resource = create_resource(config)
self.assertEqual(resource.attributes[PROCESS_PID], 99999)

def test_multiple_detector_entries_run_process_once(self):
"""Multiple detector list entries each with process={} should still work."""
config = ResourceConfig(
detection_development=ExperimentalResourceDetection(
detectors=[
ExperimentalResourceDetector(process={}),
ExperimentalResourceDetector(process={}),
]
)
)
resource = create_resource(config)
self.assertEqual(resource.attributes[PROCESS_PID], os.getpid())
Loading