Skip to content

Commit 64ccb86

Browse files
committed
Make scope matcher generic per Lukas suggestion
1 parent 8b90f2f commit 64ccb86

3 files changed

Lines changed: 13 additions & 12 deletions

File tree

opentelemetry-sdk/benchmarks/trace/test_benchmark_trace.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
TracerProvider,
2222
_default_tracer_configurator,
2323
_RuleBasedTracerConfigurator,
24-
_tracer_name_matches_glob,
24+
_scope_name_matches_glob,
2525
_TracerConfig,
2626
sampling,
2727
)
@@ -73,7 +73,7 @@ def tracer_configurator(tracer_scope):
7373
return _RuleBasedTracerConfigurator(
7474
rules=[
7575
(
76-
_tracer_name_matches_glob(glob_pattern=str(i)),
76+
_scope_name_matches_glob(glob_pattern=str(i)),
7777
_TracerConfig(is_enabled=True),
7878
)
7979
for i in range(num_tracer_configurator_rules)

opentelemetry-sdk/src/opentelemetry/sdk/trace/__init__.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,17 +1240,18 @@ def start_span( # pylint: disable=too-many-locals
12401240

12411241

12421242
_TracerConfiguratorT = Callable[[InstrumentationScope], _TracerConfig]
1243-
_TracerConfiguratorRulesPredicateT = Callable[[InstrumentationScope], bool]
1243+
_InstrumentationScopePredicateT = Callable[[InstrumentationScope], bool]
12441244
_TracerConfiguratorRulesT = Sequence[
1245-
tuple[_TracerConfiguratorRulesPredicateT, _TracerConfig]
1245+
tuple[_InstrumentationScopePredicateT, _TracerConfig]
12461246
]
12471247

12481248

1249-
def _tracer_name_matches_glob(
1249+
# TODO: share this with configurators for other signals
1250+
def _scope_name_matches_glob(
12501251
glob_pattern: str,
1251-
) -> _TracerConfiguratorRulesPredicateT:
1252-
def inner(tracer_scope: InstrumentationScope) -> bool:
1253-
return fnmatch.fnmatch(tracer_scope.name, glob_pattern)
1252+
) -> _InstrumentationScopePredicateT:
1253+
def inner(scope: InstrumentationScope) -> bool:
1254+
return fnmatch.fnmatch(scope.name, glob_pattern)
12541255

12551256
return inner
12561257

opentelemetry-sdk/tests/trace/test_trace.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
Resource,
4848
TracerProvider,
4949
_RuleBasedTracerConfigurator,
50-
_tracer_name_matches_glob,
50+
_scope_name_matches_glob,
5151
_TracerConfig,
5252
)
5353
from opentelemetry.sdk.trace.id_generator import RandomIdGenerator
@@ -2236,11 +2236,11 @@ def test_rule_based_tracer_configurator(self):
22362236
# pylint: disable=protected-access
22372237
rules = [
22382238
(
2239-
_tracer_name_matches_glob(glob_pattern="module_name"),
2239+
_scope_name_matches_glob(glob_pattern="module_name"),
22402240
_TracerConfig(is_enabled=True),
22412241
),
22422242
(
2243-
_tracer_name_matches_glob(glob_pattern="other_module_name"),
2243+
_scope_name_matches_glob(glob_pattern="other_module_name"),
22442244
_TracerConfig(is_enabled=False),
22452245
),
22462246
]
@@ -2282,7 +2282,7 @@ def test_rule_based_tracer_configurator_default_when_rules_dont_match(
22822282
# pylint: disable=protected-access
22832283
rules = [
22842284
(
2285-
_tracer_name_matches_glob(glob_pattern="module_name"),
2285+
_scope_name_matches_glob(glob_pattern="module_name"),
22862286
_TracerConfig(is_enabled=False),
22872287
),
22882288
]

0 commit comments

Comments
 (0)