Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement "named" meters + Remove "Batcher" from Meter constructor #431

Merged
merged 35 commits into from
Mar 1, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
bba1fea
Named meters
lzchen Feb 19, 2020
712ccd3
Remove test
lzchen Feb 19, 2020
b50c269
fix comment
lzchen Feb 19, 2020
fd3d175
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen Feb 19, 2020
08b1117
Fix tests
lzchen Feb 19, 2020
c92f837
address comments + fix lint
lzchen Feb 19, 2020
7b8b67d
Rename MeterSource to MeterProvider
lzchen Feb 19, 2020
63824f3
black
lzchen Feb 19, 2020
16e728b
black
lzchen Feb 19, 2020
7733a87
remove black
lzchen Feb 20, 2020
b436c62
fix lint
lzchen Feb 20, 2020
d6c97f0
fix lint
lzchen Feb 20, 2020
a2f2e0f
fix lint
lzchen Feb 20, 2020
32cf2c1
Merge branch 'master' of https://github.com/open-telemetry/openteleme…
lzchen Feb 25, 2020
ec9c673
Merge
lzchen Feb 25, 2020
7ebd438
Rename to MeterProvider, remove Batcher from constructor
lzchen Feb 25, 2020
27d75ba
fix mypy
lzchen Feb 25, 2020
08095b6
black
lzchen Feb 25, 2020
6a743c7
Black
lzchen Feb 25, 2020
e226eda
address comments
lzchen Feb 27, 2020
c7432ef
update tests
lzchen Feb 27, 2020
60b2f38
merge
lzchen Feb 27, 2020
bd53f84
fix tests
lzchen Feb 27, 2020
6f6a37d
Fix tests
lzchen Feb 27, 2020
4770ec4
black
lzchen Feb 27, 2020
0f36b31
remove black
lzchen Feb 27, 2020
4f4632b
ADDRESS COMMENTS
lzchen Feb 27, 2020
e591a39
black
lzchen Feb 27, 2020
0878f5d
fix lint
lzchen Feb 27, 2020
584d996
fix example
lzchen Feb 27, 2020
f854923
Fix lint
lzchen Feb 27, 2020
4df2553
merge
lzchen Feb 28, 2020
40ee67b
fix labelset
lzchen Feb 28, 2020
0b93285
fix lint
lzchen Feb 28, 2020
3735d88
set to none
lzchen Feb 29, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ from opentelemetry.sdk.metrics import Counter, MeterProvider
from opentelemetry.sdk.metrics.export import ConsoleMetricsExporter
from opentelemetry.sdk.metrics.export.controller import PushController

metrics.set_preferred_meter_source_implementation(lambda _: MeterProvider())
metrics.set_preferred_meter_provider_implementation(lambda _: MeterProvider())
meter = metrics.get_meter(__name__)
exporter = ConsoleMetricsExporter()
controller = PushController(meter, exporter, 5)
Expand Down
2 changes: 1 addition & 1 deletion examples/metrics/record.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion examples/metrics/simple_example.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
5 changes: 4 additions & 1 deletion ext/opentelemetry-ext-flask/tests/test_flask_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ def assert_environ():

def test_simple(self):
expected_attrs = expected_attributes(
{"http.target": "/hello/123", "http.route": "/hello/<int:helloid>"}
{
"http.target": "/hello/123",
"http.route": "/hello/<int:helloid>",
}
)
resp = self.client.get("/hello/123")
self.assertEqual(200, resp.status_code)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ def attach(self, context: Context) -> object:
def get_current(self) -> Context:
"""See `opentelemetry.context.RuntimeContext.get_current`."""
if not hasattr(self._current_context, self._CONTEXT_KEY):
setattr(self._current_context, self._CONTEXT_KEY, Context())
setattr(
self._current_context, self._CONTEXT_KEY, Context(),
)
context = getattr(
self._current_context, self._CONTEXT_KEY
) # type: Context
Expand Down
26 changes: 13 additions & 13 deletions opentelemetry-api/src/opentelemetry/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -379,8 +379,8 @@ def get_label_set(self, labels: Dict[str, str]) -> "LabelSet":
[Type[MeterProvider]], Optional[MeterProvider]
]

_METER_SOURCE = None
_METER_SOURCE_FACTORY = None
_METER_PROVIDER = None
_METER_PROVIDER_FACTORY = None


def get_meter(
Expand All @@ -402,13 +402,13 @@ def meter_provider() -> MeterProvider:

If there isn't one set yet, a default will be loaded.
"""
global _METER_SOURCE, _METER_SOURCE_FACTORY # pylint:disable=global-statement
global _METER_PROVIDER, _METER_PROVIDER_FACTORY # pylint:disable=global-statement

if _METER_SOURCE is None:
if _METER_PROVIDER is None:
# pylint:disable=protected-access
try:
_METER_SOURCE = loader._load_impl(
MeterProvider, _METER_SOURCE_FACTORY # type: ignore
_METER_PROVIDER = loader._load_impl(
MeterProvider, _METER_PROVIDER_FACTORY # type: ignore
)
except TypeError:
lzchen marked this conversation as resolved.
Show resolved Hide resolved
# if we raised an exception trying to instantiate an
Expand All @@ -417,10 +417,10 @@ def meter_provider() -> MeterProvider:
"Unable to instantiate MeterProvider from meter provider factory.",
exc_info=True,
)
_METER_SOURCE = DefaultMeterProvider()
del _METER_SOURCE_FACTORY
_METER_PROVIDER = DefaultMeterProvider()
del _METER_PROVIDER_FACTORY
Copy link
Member

Choose a reason for hiding this comment

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

can we set this to none?


return _METER_SOURCE
return _METER_PROVIDER


def set_preferred_meter_provider_implementation(
Expand All @@ -435,9 +435,9 @@ def set_preferred_meter_provider_implementation(
Args:
factory: Callback that should create a new :class:`MeterProvider` instance.
"""
global _METER_SOURCE_FACTORY # pylint:disable=global-statement
global _METER_PROVIDER_FACTORY # pylint:disable=global-statement

if _METER_SOURCE:
if _METER_PROVIDER:
raise RuntimeError("MeterProvider already loaded.")

_METER_SOURCE_FACTORY = factory
_METER_PROVIDER_FACTORY = factory
2 changes: 1 addition & 1 deletion opentelemetry-api/src/opentelemetry/util/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-api/tests/test_implementation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
4 changes: 3 additions & 1 deletion opentelemetry-api/tests/trace/test_sampling.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,4 +235,6 @@ def test_probability_sampler_limits(self):
# Check that the higest effective sampling rate is actually lower than
# the highest theoretical sampling rate. If this test fails the test
# above is wrong.
self.assertLess(almost_almost_always_on.bound, 0xFFFFFFFFFFFFFFFF)
self.assertLess(
almost_almost_always_on.bound, 0xFFFFFFFFFFFFFFFF,
)
3 changes: 2 additions & 1 deletion opentelemetry-sdk/src/opentelemetry/sdk/metrics/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -263,6 +263,7 @@ class Meter(metrics_api.Meter):

Args:
instrumentation_info: The `InstrumentationInfo` for this meter.
lzchen marked this conversation as resolved.
Show resolved Hide resolved
stateful: Indicates whether the meter is stateful.
"""

def __init__(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/export/test_export.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/test_implementation.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion opentelemetry-sdk/tests/metrics/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2019, OpenTelemetry Authors
# Copyright 2020, OpenTelemetry Authors
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down