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

Remove custom arguments in object.__new__ of BaseInstrumentor #1439

Merged
merged 33 commits into from
Feb 28, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
c61615a
Add a test case to reproduce the issue
rbagd Nov 11, 2022
70154e8
Fix the class initialization when parameters are provided
rbagd Nov 11, 2022
3604bb6
Merge branch 'main' into main
rbagd Nov 14, 2022
d6407b6
Merge branch 'main' into main
srikanthccv Nov 15, 2022
456bb3e
Merge branch 'open-telemetry:main' into main
rbagd Nov 15, 2022
680da64
Update CHANGELOG.md
rbagd Nov 15, 2022
2755ade
Fix linting issues
rbagd Nov 15, 2022
f5e3c15
Merge branch 'main' into main
rbagd Nov 16, 2022
c91935a
Merge branch 'main' into main
rbagd Nov 17, 2022
bf2ce47
Merge branch 'main' into main
ocelotl Nov 18, 2022
8179388
Additional test case which inits SystemMetricsInstrumentor twice
rbagd Nov 18, 2022
e272278
Merge branch 'main' into main
rbagd Nov 21, 2022
da28c70
Merge branch 'main' into main
rbagd Nov 22, 2022
5b9bedc
Merge branch 'main' into main
rbagd Nov 23, 2022
719ecf7
Merge branch 'main' into main
rbagd Nov 24, 2022
aa84b83
Merge branch 'main' into main
rbagd Nov 29, 2022
00c784f
Merge branch 'main' into main
rbagd Dec 4, 2022
3bda030
Merge branch 'main' into main
rbagd Dec 5, 2022
2b6dfe0
Merge branch 'main' into main
srikanthccv Dec 5, 2022
382e7da
Merge branch 'main' into main
rbagd Dec 7, 2022
d6b87df
Merge branch 'main' into main
rbagd Dec 9, 2022
52515a1
Merge branch 'main' into main
srikanthccv Dec 10, 2022
15cdc23
Merge branch 'main' into main
rbagd Feb 11, 2023
54e2135
Merge branch 'main' into main
srikanthccv Feb 13, 2023
2d91ee1
Merge branch 'main' into main
rbagd Feb 15, 2023
7d18620
Merge branch 'main' into main
srikanthccv Feb 18, 2023
7d7da96
Updated linting following update to black style
rbagd Feb 22, 2023
4aa3fa1
Merge branch 'main' into main
rbagd Feb 22, 2023
2fe9270
Merge branch 'main' into main
rbagd Feb 23, 2023
bded09e
Moved changelog entry to unreleased section
rbagd Feb 23, 2023
b01964a
Merge branch 'main' into main
rbagd Feb 24, 2023
426276f
Merge branch 'main' into main
lzchen Feb 27, 2023
75357c7
Merge branch 'main' into main
srikanthccv Feb 28, 2023
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: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Fix Flask instrumentation to only close the span if it was created by the same thread.
([#1654](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1654))
- `opentelemetry-instrumentation-system-metrics` Fix initialization of the instrumentation class when configuration is provided
([#1438](https://github.com/open-telemetry/opentelemetry-python-contrib/pull/1439))

## Version 1.16.0/0.37b0 (2023-02-17)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,31 @@ def setUp(self):
)
self._patch_net_connections.start()

# Reset the singleton class on each test run
SystemMetricsInstrumentor._instance = None

def tearDown(self):
super().tearDown()
self._patch_net_connections.stop()
SystemMetricsInstrumentor().uninstrument()

def test_system_metrics_instrumentor_initialization(self):
try:
SystemMetricsInstrumentor()
SystemMetricsInstrumentor(config={})
except Exception as error: # pylint: disable=broad-except
self.fail(f"Unexpected exception {error} raised")

SystemMetricsInstrumentor._instance = None

try:
SystemMetricsInstrumentor(config={})
SystemMetricsInstrumentor()
except Exception as error: # pylint: disable=broad-except
self.fail(f"Unexpected exception {error} raised")

SystemMetricsInstrumentor().instrument()

def test_system_metrics_instrument(self):
reader = InMemoryMetricReader()
meter_provider = MeterProvider(metric_readers=[reader])
Expand Down Expand Up @@ -103,6 +123,35 @@ def test_system_metrics_instrument(self):
self.assertIn(observer, observer_names)
observer_names.remove(observer)

def test_runtime_metrics_instrument(self):
runtime_config = {
"runtime.memory": ["rss", "vms"],
"runtime.cpu.time": ["user", "system"],
"runtime.gc_count": None,
}

reader = InMemoryMetricReader()
meter_provider = MeterProvider(metric_readers=[reader])
runtime_metrics = SystemMetricsInstrumentor(config=runtime_config)
runtime_metrics.instrument(meter_provider=meter_provider)

metric_names = []
for resource_metrics in reader.get_metrics_data().resource_metrics:
for scope_metrics in resource_metrics.scope_metrics:
for metric in scope_metrics.metrics:
metric_names.append(metric.name)
self.assertEqual(len(metric_names), 3)

observer_names = [
f"runtime.{self.implementation}.memory",
f"runtime.{self.implementation}.cpu_time",
f"runtime.{self.implementation}.gc_count",
]

for observer in metric_names:
self.assertIn(observer, observer_names)
observer_names.remove(observer)

def _assert_metrics(self, observer_name, reader, expected):
assertions = 0
# pylint: disable=too-many-nested-blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class BaseInstrumentor(ABC):

def __new__(cls, *args, **kwargs):
if cls._instance is None:
cls._instance = object.__new__(cls, *args, **kwargs)
cls._instance = object.__new__(cls)

return cls._instance

Expand Down