Skip to content

Commit 13d5735

Browse files
committed
Update opentelemetry_metrics_exporter entrypoint to a MetricReader factory
1 parent d8490c5 commit 13d5735

File tree

13 files changed

+229
-44
lines changed

13 files changed

+229
-44
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
- Modify Prometheus exporter to translate non-monotonic Sums into Gauges
1111
([#3306](https://github.com/open-telemetry/opentelemetry-python/pull/3306))
12+
- Update `opentelemetry_metrics_exporter` entrypoint to a MetricReader factory
13+
([#3412](https://github.com/open-telemetry/opentelemetry-python/pull/3412))
14+
1215

1316

1417
## Version 1.19.0/0.40b0 (2023-07-13)

exporter/opentelemetry-exporter-otlp-proto-grpc/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test = [
4545
otlp_proto_grpc = "opentelemetry.exporter.otlp.proto.grpc._log_exporter:OTLPLogExporter"
4646

4747
[project.entry-points.opentelemetry_metrics_exporter]
48-
otlp_proto_grpc = "opentelemetry.exporter.otlp.proto.grpc.metric_exporter:OTLPMetricExporter"
48+
otlp_proto_grpc = "opentelemetry.exporter.otlp.proto.grpc.metric_exporter:_otlp_metric_exporter_entrypoint"
4949

5050
[project.entry-points.opentelemetry_traces_exporter]
5151
otlp_proto_grpc = "opentelemetry.exporter.otlp.proto.grpc.trace_exporter:OTLPSpanExporter"

exporter/opentelemetry-exporter-otlp-proto-grpc/src/opentelemetry/exporter/otlp/proto/grpc/metric_exporter/__init__.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,9 @@
5454
Metric,
5555
MetricExporter,
5656
MetricExportResult,
57+
MetricReader,
5758
MetricsData,
59+
PeriodicExportingMetricReader,
5860
ResourceMetrics,
5961
ScopeMetrics,
6062
)
@@ -102,7 +104,6 @@ def __init__(
102104
preferred_aggregation: Dict[type, Aggregation] = None,
103105
max_export_batch_size: Optional[int] = None,
104106
):
105-
106107
if insecure is None:
107108
insecure = environ.get(OTEL_EXPORTER_OTLP_METRICS_INSECURE)
108109
if insecure is not None:
@@ -260,3 +261,8 @@ def _exporting(self) -> str:
260261
def force_flush(self, timeout_millis: float = 10_000) -> bool:
261262
"""Nothing is buffered in this exporter, so this method does nothing."""
262263
return True
264+
265+
266+
def _otlp_metric_exporter_entrypoint() -> MetricReader:
267+
"""Implementation of opentelemetry_metrics_exporter entrypoint"""
268+
return PeriodicExportingMetricReader(OTLPMetricExporter())
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest import TestCase
16+
17+
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
18+
OTLPLogExporter,
19+
)
20+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import (
21+
_otlp_metric_exporter_entrypoint,
22+
)
23+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
24+
OTLPSpanExporter,
25+
)
26+
from opentelemetry.sdk._configuration import _import_exporters
27+
28+
29+
class TestEntrypoints(TestCase):
30+
def test_import_exporters(self) -> None:
31+
"""
32+
Tests that the entrypoints can be loaded and don't have a typo in the names
33+
"""
34+
(
35+
trace_exporters,
36+
metric_exporters,
37+
logs_exporters,
38+
) = _import_exporters(
39+
trace_exporter_names=["otlp_proto_grpc"],
40+
metric_exporter_names=["otlp_proto_grpc"],
41+
log_exporter_names=["otlp_proto_grpc"],
42+
)
43+
44+
self.assertEqual(
45+
trace_exporters,
46+
{"otlp_proto_grpc": OTLPSpanExporter},
47+
)
48+
self.assertEqual(
49+
metric_exporters,
50+
{"otlp_proto_grpc": _otlp_metric_exporter_entrypoint},
51+
)
52+
self.assertEqual(
53+
logs_exporters,
54+
{"otlp_proto_grpc": OTLPLogExporter},
55+
)

exporter/opentelemetry-exporter-otlp-proto-http/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ test = [
4545
otlp_proto_http = "opentelemetry.exporter.otlp.proto.http.trace_exporter:OTLPSpanExporter"
4646

4747
[project.entry-points.opentelemetry_metrics_exporter]
48-
otlp_proto_http = "opentelemetry.exporter.otlp.proto.http.metric_exporter:OTLPMetricExporter"
48+
otlp_proto_http = "opentelemetry.exporter.otlp.proto.http.metric_exporter:_otlp_metric_exporter_entrypoint"
4949

5050
[project.entry-points.opentelemetry_logs_exporter]
5151
otlp_proto_http = "opentelemetry.exporter.otlp.proto.http._log_exporter:OTLPLogExporter"

exporter/opentelemetry-exporter-otlp-proto-http/src/opentelemetry/exporter/otlp/proto/http/metric_exporter/__init__.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,9 @@
6363
AggregationTemporality,
6464
MetricExporter,
6565
MetricExportResult,
66+
MetricReader,
6667
MetricsData,
68+
PeriodicExportingMetricReader,
6769
)
6870
from opentelemetry.sdk.metrics.export import ( # noqa: F401
6971
Gauge,
@@ -101,7 +103,6 @@ def _expo(*args, **kwargs):
101103

102104

103105
class OTLPMetricExporter(MetricExporter, OTLPMetricExporterMixin):
104-
105106
_MAX_RETRY_TIMEOUT = 64
106107

107108
def __init__(
@@ -182,7 +183,6 @@ def export(
182183
) -> MetricExportResult:
183184
serialized_data = encode_metrics(metrics_data)
184185
for delay in _expo(max_value=self._MAX_RETRY_TIMEOUT):
185-
186186
if delay == self._MAX_RETRY_TIMEOUT:
187187
return MetricExportResult.FAILURE
188188

@@ -247,3 +247,8 @@ def _append_metrics_path(endpoint: str) -> str:
247247
if endpoint.endswith("/"):
248248
return endpoint + DEFAULT_METRICS_EXPORT_PATH
249249
return endpoint + f"/{DEFAULT_METRICS_EXPORT_PATH}"
250+
251+
252+
def _otlp_metric_exporter_entrypoint() -> MetricReader:
253+
"""Implementation of opentelemetry_metrics_exporter entrypoint"""
254+
return PeriodicExportingMetricReader(OTLPMetricExporter())
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest import TestCase
16+
17+
from opentelemetry.exporter.otlp.proto.http._log_exporter import (
18+
OTLPLogExporter,
19+
)
20+
from opentelemetry.exporter.otlp.proto.http.metric_exporter import (
21+
_otlp_metric_exporter_entrypoint,
22+
)
23+
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
24+
OTLPSpanExporter,
25+
)
26+
from opentelemetry.sdk._configuration import _import_exporters
27+
28+
29+
class TestEntrypoints(TestCase):
30+
def test_import_exporters(self) -> None:
31+
"""
32+
Tests that the entrypoints can be loaded and don't have a typo in the names
33+
"""
34+
(
35+
trace_exporters,
36+
metric_exporters,
37+
logs_exporters,
38+
) = _import_exporters(
39+
trace_exporter_names=["otlp_proto_http"],
40+
metric_exporter_names=["otlp_proto_http"],
41+
log_exporter_names=["otlp_proto_http"],
42+
)
43+
44+
self.assertEqual(
45+
trace_exporters,
46+
{"otlp_proto_http": OTLPSpanExporter},
47+
)
48+
self.assertEqual(
49+
metric_exporters,
50+
{"otlp_proto_http": _otlp_metric_exporter_entrypoint},
51+
)
52+
self.assertEqual(
53+
logs_exporters,
54+
{"otlp_proto_http": OTLPLogExporter},
55+
)

exporter/opentelemetry-exporter-otlp/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ dependencies = [
3434
otlp = "opentelemetry.exporter.otlp.proto.grpc._log_exporter:OTLPLogExporter"
3535

3636
[project.entry-points.opentelemetry_metrics_exporter]
37-
otlp = "opentelemetry.exporter.otlp.proto.grpc.metric_exporter:OTLPMetricExporter"
37+
otlp = "opentelemetry.exporter.otlp.proto.grpc.metric_exporter:_otlp_metric_exporter_entrypoint"
3838

3939
[project.entry-points.opentelemetry_traces_exporter]
4040
otlp = "opentelemetry.exporter.otlp.proto.grpc.trace_exporter:OTLPSpanExporter"
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Copyright The OpenTelemetry Authors
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
from unittest import TestCase
16+
17+
from opentelemetry.exporter.otlp.proto.grpc._log_exporter import (
18+
OTLPLogExporter,
19+
)
20+
from opentelemetry.exporter.otlp.proto.grpc.metric_exporter import (
21+
_otlp_metric_exporter_entrypoint,
22+
)
23+
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
24+
OTLPSpanExporter,
25+
)
26+
from opentelemetry.sdk._configuration import _import_exporters
27+
28+
29+
class TestEntrypoints(TestCase):
30+
def test_import_exporters(self) -> None:
31+
"""
32+
Tests that the entrypoints can be loaded and don't have a typo in the names
33+
"""
34+
(
35+
trace_exporters,
36+
metric_exporters,
37+
logs_exporters,
38+
) = _import_exporters(
39+
trace_exporter_names=["otlp"],
40+
metric_exporter_names=["otlp"],
41+
log_exporter_names=["otlp"],
42+
)
43+
44+
self.assertEqual(
45+
trace_exporters,
46+
{"otlp": OTLPSpanExporter},
47+
)
48+
self.assertEqual(
49+
metric_exporters,
50+
{"otlp": _otlp_metric_exporter_entrypoint},
51+
)
52+
self.assertEqual(
53+
logs_exporters,
54+
{"otlp": OTLPLogExporter},
55+
)

opentelemetry-sdk/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ console = "opentelemetry.sdk._logs.export:ConsoleLogExporter"
5858
sdk_meter_provider = "opentelemetry.sdk.metrics:MeterProvider"
5959

6060
[project.entry-points.opentelemetry_metrics_exporter]
61-
console = "opentelemetry.sdk.metrics.export:ConsoleMetricExporter"
61+
console = "opentelemetry.sdk.metrics._internal.export:_console_metric_exporter_entrypoint"
6262

6363
[project.entry-points.opentelemetry_tracer_provider]
6464
sdk_tracer_provider = "opentelemetry.sdk.trace:TracerProvider"

0 commit comments

Comments
 (0)