Skip to content

Conversation

alexmojaki
Copy link
Contributor

@alexmojaki alexmojaki commented Sep 5, 2025

Description

Fixes #3054

Changes opentelemetry.util._importlib_metadata.entry_points to a version with some caching instead of just an alias of the original importlib_metadata.entry_points.

Type of change

Performance improvement, shouldn't break anything, unless it's possible for the result of the original importlib_metadata.entry_points() to change midway through a program run in a way that affects OTel, i.e. if some OTel entry point is registered at runtime.

How Has This Been Tested?

Run this script with and without this PR:

import time start_time = time.perf_counter() from opentelemetry import context, propagate from opentelemetry.sdk.resources import Resource # mark imports as used for formatter str(context) str(propagate) Resource.create() end_time = time.perf_counter() print(end_time - start_time)

I personally see a ~10% performance improvement in this repo, but I know it can be significantly more in environments with many packages installed.

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 existing tests should suffice, they use the new code implicitly
  • Documentation has been updated I don't think this needs docs, but there's a docstring
@alexmojaki alexmojaki requested a review from a team as a code owner September 5, 2025 15:43
@alexmojaki alexmojaki changed the title Cache importlib_metadata.entry_points Cache importlib_metadata.entry_points Sep 5, 2025
Copy link
Member

@emdneto emdneto left a comment

Choose a reason for hiding this comment

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

Looks good.
Created a simple benchmark test and got an Overall speedup of 6.43x

opentelemetry-sdk/benchmarks/test_entrypoints.py

def test_resource_entry_points(benchmark): def create_some_resources(): from opentelemetry import context, propagate from opentelemetry.sdk.resources import Resource str(context) str(propagate) Resource.create() benchmark(create_some_resources)

tox -e benchmark-opentelemetry-sdk -- -k 'test_resource_entry_points'

@xrmx xrmx merged commit c71c4a4 into open-telemetry:main Sep 9, 2025
371 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

4 participants