From a659966b950ed055f270e8700f9e39e36e5c4eda Mon Sep 17 00:00:00 2001 From: Alex Boten Date: Tue, 25 Jan 2022 14:39:40 -0800 Subject: [PATCH] fixing documentation and return value (#2399) --- docs/examples/metrics/example.py | 6 ++++-- docs/getting_started/metrics_example.py | 10 +++++++--- .../src/opentelemetry/sdk/_metrics/export/__init__.py | 5 ++++- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/docs/examples/metrics/example.py b/docs/examples/metrics/example.py index 359bb31bf35..7242d976d93 100644 --- a/docs/examples/metrics/example.py +++ b/docs/examples/metrics/example.py @@ -3,12 +3,14 @@ OTLPMetricExporter, ) from opentelemetry.sdk._metrics import MeterProvider +from opentelemetry.sdk._metrics.export import PeriodicExportingMetricReader -provider = MeterProvider() exporter = OTLPMetricExporter(insecure=True) -# TODO: fill in details for metric reader +reader = PeriodicExportingMetricReader(exporter) +provider = MeterProvider(metric_readers=[reader]) set_meter_provider(provider) meter = get_meter_provider().get_meter("getting-started") counter = meter.create_counter("first_counter") +counter.add(1) # TODO: fill in details for additional metrics diff --git a/docs/getting_started/metrics_example.py b/docs/getting_started/metrics_example.py index ccbe465d1d2..140dc0004be 100644 --- a/docs/getting_started/metrics_example.py +++ b/docs/getting_started/metrics_example.py @@ -17,13 +17,17 @@ from opentelemetry._metrics import get_meter_provider, set_meter_provider from opentelemetry.sdk._metrics import MeterProvider -from opentelemetry.sdk._metrics.export import ConsoleMetricExporter +from opentelemetry.sdk._metrics.export import ( + ConsoleMetricExporter, + PeriodicExportingMetricReader, +) -provider = MeterProvider() exporter = ConsoleMetricExporter() -# TODO: fill in details for metric reader +reader = PeriodicExportingMetricReader(exporter) +provider = MeterProvider(metric_readers=[reader]) set_meter_provider(provider) meter = get_meter_provider().get_meter("getting-started") counter = meter.create_counter("first_counter") +counter.add(1) # TODO: fill in details for additional metrics diff --git a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py index 13494347a87..284629330f8 100644 --- a/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py +++ b/opentelemetry-sdk/src/opentelemetry/sdk/_metrics/export/__init__.py @@ -154,6 +154,8 @@ def _ticker(self) -> None: self.collect() def _receive_metrics(self, metrics: Iterable[Metric]) -> None: + if metrics is None: + return token = attach(set_value(_SUPPRESS_INSTRUMENTATION_KEY, True)) try: self._exporter.export(metrics) @@ -172,4 +174,5 @@ def _shutdown(): self._shutdown_event.set() self._daemon_thread.join() - return self._exporter.shutdown() + self._exporter.shutdown() + return True