Skip to content

feat(config): wire id_generator from declarative configuration to TracerProvider#5363

Open
aman-panjwani wants to merge 6 commits into
open-telemetry:mainfrom
aman-panjwani:feat/config-wire-id-generator
Open

feat(config): wire id_generator from declarative configuration to TracerProvider#5363
aman-panjwani wants to merge 6 commits into
open-telemetry:mainfrom
aman-panjwani:feat/config-wire-id-generator

Conversation

@aman-panjwani

Copy link
Copy Markdown
Contributor

Description

Wires the id_generator field from declarative configuration to TracerProvider, closing the parity gap with Java/JS SDKs. Depends on #5333 (merged) which added IdGenerator to models.py.

Fixes #5334

Changes

  • Added _ID_GENERATOR_REGISTRY and _create_id_generator in _tracer_provider.py using the existing _resolve_component helper
  • Built-in random resolves to RandomIdGenerator
  • Unknown names load from the opentelemetry_id_generator entry point group (same group OTEL_PYTHON_ID_GENERATOR uses today)
  • Threaded id_generator through create_tracer_provider - absent config passes None so the SDK applies its own RandomIdGenerator default

Tests Added

  • test_absent_id_generator_uses_sdk_default - omitted config → SDK default RandomIdGenerator
  • test_builtin_random_id_generator - built-in randomRandomIdGenerator
  • test_plugin_id_generator_loaded_via_entry_point - unknown name → loaded from opentelemetry_id_generator entry point group
  • test_unknown_id_generator_raises_configuration_error - unknown name with no matching entry point → ConfigurationError
  • test_empty_id_generator_raises_configuration_error - empty config → ConfigurationError

Type of change

  • New feature (non-breaking change which adds functionality)

How Has This Been Tested?

  • Ran tox -e ruff - linter and formatter passing

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

@aman-panjwani aman-panjwani requested a review from a team as a code owner June 26, 2026 15:31
@MikeGoldsmith MikeGoldsmith added the config Issues and PRs related to implementing Declarative Config label Jun 30, 2026
@MikeGoldsmith MikeGoldsmith moved this to Ready for review in Python PR digest Jun 30, 2026
)
id_generator = (
_create_id_generator(config.id_generator)
if config is not None and config.id_generator is not None

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.

should we check using hasattr, to see if id_generator exists on config or not?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yeah! Added hasattr check to guard against configs that don't have the id_generator

@MikeGoldsmith MikeGoldsmith left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good, thanks @aman-panjwani. I've left a couple of small suggestions 👍🏻

Comment thread .changelog/5363.added
@@ -0,0 +1 @@
`opentelemetry-sdk`: wire id_generator from declarative configuration to TracerProvider

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The filename should be 5363.added, as this is a new feature.

Comment on lines +365 to +366
name = next(iter(config.additional_properties))
return load_entry_point("opentelemetry_id_generator", name)()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should pass in kwargs here so any additional_properties from the config are passed in.

Suggested change
name = next(iter(config.additional_properties))
return load_entry_point("opentelemetry_id_generator", name)()
name, plugin_config = next(iter(config.additional_properties.items()))
return load_entry_point("opentelemetry_id_generator", name)(**(plugin_config or {}))

@aman-panjwani aman-panjwani force-pushed the feat/config-wire-id-generator branch from dab14fa to 4dc7a06 Compare July 5, 2026 12:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config Issues and PRs related to implementing Declarative Config

Projects

Status: Ready for review

Development

Successfully merging this pull request may close these issues.

feat(config): wire id_generator from declarative configuration to TracerProvider

3 participants