Skip to content

opentelemetry-sdk: cache tracer configs in Tracer#5007

Open
xrmx wants to merge 6 commits intoopen-telemetry:mainfrom
xrmx:cache-tracer-config
Open

opentelemetry-sdk: cache tracer configs in Tracer#5007
xrmx wants to merge 6 commits intoopen-telemetry:mainfrom
xrmx:cache-tracer-config

Conversation

@xrmx
Copy link
Contributor

@xrmx xrmx commented Mar 23, 2026

Description

Instead of creating the TracerConfig at each start_span call, just compute it on change. This changes an internal interface.

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update

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

  • Test A

Does This PR Require a Contrib Repo Change?

  • Yes. - Link to PR:
  • No.

Checklist:

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

Instead of creating the TracerConfig at each start_span call, just
compute it on change.
@xrmx xrmx requested a review from a team as a code owner March 23, 2026 17:08
@xrmx xrmx moved this to Ready for review in Python PR digest Mar 23, 2026
@xrmx
Copy link
Contributor Author

xrmx commented Mar 23, 2026

Benchmarks

-------------------------------------------------------------------------------------------------------- benchmark: 6 tests -------------------------------------------------------------------------------------------------------
Name (time in us)                                                 Min                 Max               Mean            StdDev             Median               IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_simple_start_span_with_tracer_configurator_rules[None]     12.7530 (1.0)      39.7900 (1.53)     14.0253 (1.0)      0.9216 (1.46)     13.8770 (1.0)      0.7010 (1.17)      744;279       71.3000 (1.0)        8740           1
test_simple_start_span_with_tracer_configurator_rules[10]       12.8790 (1.01)     25.9930 (1.0)      14.2303 (1.01)     0.6878 (1.09)     14.1430 (1.02)     0.5973 (1.0)        374;75       70.2724 (0.99)       2909           1
test_simple_start_span_with_tracer_configurator_rules[1]        13.0920 (1.03)     28.6730 (1.10)     14.3815 (1.03)     0.6356 (1.01)     14.3170 (1.03)     0.6070 (1.02)     1181;152       69.5339 (0.98)       7239           1
test_simple_start_span_with_tracer_configurator_rules[0]        13.1550 (1.03)     30.4540 (1.17)     14.3915 (1.03)     0.6302 (1.0)      14.3320 (1.03)     0.6125 (1.03)     2882;316       69.4855 (0.97)      17352           1
test_simple_start_span_with_tracer_configurator_rules[50]       13.2760 (1.04)     27.8670 (1.07)     14.3546 (1.02)     0.8041 (1.28)     14.2400 (1.03)     0.6080 (1.02)        49;18       69.6643 (0.98)        727           1

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

after

-------------------------------------------------------------------------------------------------------- benchmark: 6 tests -------------------------------------------------------------------------------------------------------
Name (time in us)                                                 Min                 Max               Mean            StdDev             Median               IQR            Outliers  OPS (Kops/s)            Rounds  Iterations
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_simple_start_span_with_tracer_configurator_rules[0]      12.7130 (1.0)       34.4780 (1.0)      13.9008 (1.0)      0.6829 (1.0)      13.8050 (1.0)      0.5950 (1.14)     1285;287       71.9383 (1.0)        9127           1
test_simple_start_span_with_tracer_configurator_rules[50]     12.8570 (1.01)      85.8870 (2.49)     14.1029 (1.01)     1.0369 (1.52)     13.9990 (1.01)     0.5490 (1.05)      429;429       70.9077 (0.99)      14893           1
test_simple_start_span_with_tracer_configurator_rules[10]     12.8640 (1.01)      57.6480 (1.67)     14.0218 (1.01)     1.1011 (1.61)     13.9040 (1.01)     0.5220 (1.0)       459;583       71.3176 (0.99)      20711           1
test_simple_start_span_with_tracer_configurator_rules[1]      12.9070 (1.02)     186.0220 (5.40)     14.4462 (1.04)     2.6857 (3.93)     14.0930 (1.02)     0.6400 (1.23)     593;1007       69.2222 (0.96)      19222           1
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@xrmx xrmx force-pushed the cache-tracer-config branch from 116b776 to 2dbca74 Compare March 25, 2026 09:49
Copy link
Member

@pmcollins pmcollins left a comment

Choose a reason for hiding this comment

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

Looks like a positive change overall, thanks for doing this.

)

with self._tracers_lock:
self._tracers[instrumentation_scope] = tracer
Copy link
Member

Choose a reason for hiding this comment

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

If there's already a Tracer with this instrumentation scope registered in _tracers, should it be returned? Looks like we're always creating a new Tracer, and if we overwrite a Tracer that's already registered in _tracers, it gets overwritten, then it won't be iterated over in _set_tracer_configurator, and won't receive config updates, even though it could still be in use.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

3 participants