Skip to content

opentelemetry-sdk: Implement meter configurator #4966

Open
herin049 wants to merge 8 commits intoopen-telemetry:mainfrom
herin049:feat/meter-configurator
Open

opentelemetry-sdk: Implement meter configurator #4966
herin049 wants to merge 8 commits intoopen-telemetry:mainfrom
herin049:feat/meter-configurator

Conversation

@herin049
Copy link
Copy Markdown
Contributor

@herin049 herin049 commented Mar 11, 2026

Description

Follow up to #4861 to implement part of the Metrics SDK spec to support meter configuration https://opentelemetry.io/docs/specs/otel/metrics/sdk/#meterconfigurator

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?

tox -e py314-test-opentelemetry-sdk

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

@herin049 herin049 force-pushed the feat/meter-configurator branch from a5c6fa3 to 51a59ea Compare March 13, 2026 18:56
@herin049 herin049 marked this pull request as ready for review March 13, 2026 19:23
@herin049 herin049 requested a review from a team as a code owner March 13, 2026 19:23
@herin049 herin049 moved this to Ready for review in Python PR digest Mar 13, 2026
@herin049 herin049 force-pushed the feat/meter-configurator branch from bbfae71 to 6d8ddbd Compare March 24, 2026 19:36
return _MeterConfig(is_enabled=False)


class _RuleBasedMeterConfigurator:
Copy link
Copy Markdown
Contributor

@xrmx xrmx Mar 25, 2026

Choose a reason for hiding this comment

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

Unrelated to this PR but I'm thinking on making the rules updatable , WDYT?

class _RuleBasedTracerConfigurator:
    def __init__(
        self,
        *,
        rules: _TracerConfiguratorRulesT,
        default_config: _TracerConfig,
    ):
        self._rules = rules
        self._default_config = default_config

    def __call__(self, tracer_scope: InstrumentationScope) -> _TracerConfig:
        for predicate, tracer_config in list(self._rules):
            if predicate(tracer_scope):
                return tracer_config

        # if no rule matched return the default config
        return self._default_config

    def update_rules(self, rules: _TracerConfiguratorRulesT):
        self._rules = rules

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.

Sure, let me add this into the PR

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.

@xrmx Actually, we can probably make this generic to reduce code duplication. I can make this change in a later PR for the logs changes. Lmk what you think.

from typing import TypeVar, Generic, Callable

_ConfigT = TypeVar("_ConfigT")
_RulesT = list[tuple[Callable[[InstrumentationScope], bool], _ConfigT]]


class _RuleBasedConfigurator(Generic[_ConfigT]):
    def __init__(
        self,
        *,
        rules: _RulesT[_ConfigT],
        default_config: _ConfigT,
    ):
        self._rules = rules
        self._default_config = default_config

    def __call__(self, scope: InstrumentationScope) -> _ConfigT:
        for predicate, config in self._rules:
            if predicate(scope):
                return config
        return self._default_config

    def update_rules(self, rules: _RulesT[_ConfigT]) -> None:
        self._rules = rules

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.

Yeah, let's make the generic version in a later PR

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.

2 participants