Skip to content

update SDK to call version directly#5145

Draft
codeboten wants to merge 6 commits intoopen-telemetry:mainfrom
codeboten:codeboten/memory-footprint-reduction
Draft

update SDK to call version directly#5145
codeboten wants to merge 6 commits intoopen-telemetry:mainfrom
codeboten:codeboten/memory-footprint-reduction

Conversation

@codeboten
Copy link
Copy Markdown
Contributor

@codeboten codeboten commented Apr 24, 2026

Description

Removing the call to version in the resource to reduce the amount of libraries imported.

~17–27% memory reduction across all scenarios
~11–23% startup time reduction

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Ran unit tests

Does This PR Require a Contrib Repo Change?

  • No.

Checklist:

  • Followed the style guidelines of this project
  • Changelogs have been updated
  • Unit tests have been added
  • Documentation has been updated

Removing the call to version in the resource to reduce the amount of libraries imported.

~17–27% memory reduction across all scenarios
~11–23% startup time reduction

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
logger.exception(
"Failed to load resource detector '%s', skipping",
resource_detector,
extra_detector_names: Set[str] = {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The usage of set here introduces non-determinism in the ordering of resource detectors.

if "*" in extra_detector_names:
# Expand wildcard to all registered detectors except "otel" (already added)
extra_detector_names = (
set(entry_points(group="opentelemetry_resource_detector").names) # type: ignore[reportUnknownArgumentType]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here with the usage of set.

# "otel" is always included and resolves to OTELResourceDetector (defined in
# this module), so we instantiate it directly to avoid an entry_points scan
# in the common case where no extra detectors are configured.
resource_detectors: List[ResourceDetector] = [OTELResourceDetector()]
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fyi, the OTELResourceDetector should be merged last, not first.

Comment thread opentelemetry-sdk/src/opentelemetry/sdk/resources/__init__.py Outdated
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
@herin049
Copy link
Copy Markdown
Contributor

Thanks for the updates! One more small comment is that the previous behavior was to allow modifying the merge order of the "otel" resource detector by respecting its position in the resource detectors list if it is explicitly provided. This is a pretty fringe use-case, but I'd prefer to keep this behavior if possible.

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
…to method

Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Signed-off-by: Alex Boten <223565+codeboten@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants