diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index fbfccd1a4ad0..1294f0f46826 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -12,6 +12,8 @@ ([#32327](https://github.com/Azure/azure-sdk-for-python/pull/32327)) - Updated django samples with clearly artificial secret key ([#32698](https://github.com/Azure/azure-sdk-for-python/pull/32698)) +- Remove metric namespace + ([#32897](https://github.com/Azure/azure-sdk-for-python/pull/32897)) ### Other Changes diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/README.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/README.md index 612598e5ae4f..4970bf99f752 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/README.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/README.md @@ -664,7 +664,7 @@ contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additio [aad_for_ai_docs]: https://learn.microsoft.com/azure/azure-monitor/app/azure-ad-authentication?tabs=python -[api_docs]: https://azuresdkdocs.blob.core.windows.net/$web/python/azure-opentelemetry-exporter-azuremonitor/1.0.0b2/index.html +[api_docs]: https://azure.github.io/azure-sdk-for-python/monitor.html#azure-monitor-opentelemetry-exporter [exporter_samples]: https://github.com/Azure/azure-sdk-for-python/tree/main/sdk/monitor/azure-monitor-opentelemetry-exporter/samples [product_docs]: https://docs.microsoft.com/azure/azure-monitor/overview [azure_sub]: https://azure.microsoft.com/free/ diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/metrics/_exporter.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/metrics/_exporter.py index f1d6225a48d6..a7e5830b7892 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/metrics/_exporter.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/export/metrics/_exporter.py @@ -23,7 +23,6 @@ NumberDataPoint, ) from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.util.instrumentation import InstrumentationScope from azure.monitor.opentelemetry.exporter._constants import ( _AUTOCOLLECTED_INSTRUMENT_NAMES, @@ -95,7 +94,6 @@ def export( point, metric.name, resource_metric.resource, - scope_metric.scope ) if envelope is not None: envelopes.append(envelope) @@ -135,9 +133,8 @@ def _point_to_envelope( point: DataPointT, name: str, resource: Optional[Resource] = None, - scope: Optional[InstrumentationScope] = None ) -> Optional[TelemetryItem]: - envelope = _convert_point_to_envelope(point, name, resource, scope) + envelope = _convert_point_to_envelope(point, name, resource) if name in _AUTOCOLLECTED_INSTRUMENT_NAMES: envelope = _handle_std_metric_envelope(envelope, name, point.attributes) if envelope is not None: @@ -168,14 +165,10 @@ def _convert_point_to_envelope( point: DataPointT, name: str, resource: Optional[Resource] = None, - scope: Optional[InstrumentationScope] = None ) -> TelemetryItem: envelope = _utils._create_telemetry_item(point.time_unix_nano) envelope.name = _METRIC_ENVELOPE_NAME envelope.tags.update(_utils._populate_part_a_fields(resource)) - namespace = None - if scope is not None: - namespace = scope.name value = 0 count = 1 min_ = None @@ -193,11 +186,8 @@ def _convert_point_to_envelope( # truncation logic properties = _utils._filter_custom_properties(point.attributes) - if namespace is not None: - namespace = str(namespace)[:256] data_point = MetricDataPoint( name=str(name)[:1024], - namespace=namespace, value=value, count=count, min=min_, diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_exporter.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_exporter.py index b516a81982f6..b79cb15b79b4 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_exporter.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/statsbeat/_exporter.py @@ -3,7 +3,6 @@ from typing import Optional from opentelemetry.sdk.metrics.export import DataPointT from opentelemetry.sdk.resources import Resource -from opentelemetry.sdk.util.instrumentation import InstrumentationScope from azure.monitor.opentelemetry.exporter._generated.models import TelemetryItem from azure.monitor.opentelemetry.exporter import AzureMonitorMetricExporter @@ -18,7 +17,6 @@ def _point_to_envelope( point: DataPointT, name: str, resource: Optional[Resource] = None, - scope: Optional[InstrumentationScope] = None ) -> TelemetryItem: # map statsbeat name from OpenTelemetry name name = _STATSBEAT_METRIC_NAME_MAPPINGS[name] @@ -26,5 +24,5 @@ def _point_to_envelope( point, name, resource, - scope, + ) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/metrics/test_metrics.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/metrics/test_metrics.py index d27afbe2b0fe..cf8938d1d401 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/metrics/test_metrics.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/metrics/test_metrics.py @@ -212,7 +212,6 @@ def test_point_to_envelope_partA_default(self): def test_point_to_envelope_number(self): exporter = self._exporter resource = Resource.create(attributes={"asd":"test_resource"}) - scope = InstrumentationScope("test_scope") point=NumberDataPoint( attributes={ "test": "attribute", @@ -221,7 +220,7 @@ def test_point_to_envelope_number(self): time_unix_nano=1646865018558419457, value=10, ) - envelope = exporter._point_to_envelope(point, "test name", resource, scope) + envelope = exporter._point_to_envelope(point, "test name", resource) self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key) self.assertEqual(envelope.name, 'Microsoft.ApplicationInsights.Metric') self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano)) @@ -230,14 +229,12 @@ def test_point_to_envelope_number(self): self.assertEqual(envelope.data.base_data.properties['test'], 'attribute') self.assertEqual(len(envelope.data.base_data.metrics), 1) self.assertEqual(envelope.data.base_data.metrics[0].name, "test name") - self.assertEqual(envelope.data.base_data.metrics[0].namespace, "test_scope") self.assertEqual(envelope.data.base_data.metrics[0].value, 10) self.assertEqual(envelope.data.base_data.metrics[0].count, 1) def test_point_to_envelope_histogram(self): exporter = self._exporter resource = Resource.create(attributes={"asd":"test_resource"}) - scope = InstrumentationScope("test_scope") point=HistogramDataPoint( attributes={ "test": "attribute", @@ -251,7 +248,7 @@ def test_point_to_envelope_histogram(self): time_unix_nano=1646865018558419457, sum=31, ) - envelope = exporter._point_to_envelope(point, "test name", resource, scope) + envelope = exporter._point_to_envelope(point, "test name", resource) self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key) self.assertEqual(envelope.name, 'Microsoft.ApplicationInsights.Metric') self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano)) @@ -260,7 +257,6 @@ def test_point_to_envelope_histogram(self): self.assertEqual(envelope.data.base_data.properties['test'], 'attribute') self.assertEqual(len(envelope.data.base_data.metrics), 1) self.assertEqual(envelope.data.base_data.metrics[0].name, "test name") - self.assertEqual(envelope.data.base_data.metrics[0].namespace, "test_scope") self.assertEqual(envelope.data.base_data.metrics[0].value, 31) self.assertEqual(envelope.data.base_data.metrics[0].count, 7) @@ -270,7 +266,6 @@ def test_point_to_envelope_std_metric_client_duration(self): {"service.name": "testServiceName", "service.namespace": "testServiceNamespace", "service.instance.id": "testServiceInstanceId"}) - scope = InstrumentationScope("opentelemetry.instrumentation.requests") point=NumberDataPoint( attributes={ "http.status_code": 200, @@ -281,7 +276,7 @@ def test_point_to_envelope_std_metric_client_duration(self): time_unix_nano=1646865018558419457, value=15.0, ) - envelope = exporter._point_to_envelope(point, "http.client.duration", resource, scope) + envelope = exporter._point_to_envelope(point, "http.client.duration", resource) self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key) self.assertEqual(envelope.name, 'Microsoft.ApplicationInsights.Metric') self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano)) @@ -297,23 +292,22 @@ def test_point_to_envelope_std_metric_client_duration(self): self.assertIsNone(envelope.data.base_data.properties.get("custom_attr")) self.assertEqual(len(envelope.data.base_data.metrics), 1) self.assertEqual(envelope.data.base_data.metrics[0].name, "http.client.duration") - self.assertEqual(envelope.data.base_data.metrics[0].namespace, "opentelemetry.instrumentation.requests") self.assertEqual(envelope.data.base_data.metrics[0].value, 15.0) # target point.attributes.pop("peer.service", None) point.attributes["net.peer.name"] = None - envelope = exporter._point_to_envelope(point, "http.client.duration", resource, scope) + envelope = exporter._point_to_envelope(point, "http.client.duration", resource) self.assertEqual(envelope.data.base_data.properties['dependency/target'], None) point.attributes["net.peer.name"] = "test_peer_name" point.attributes["net.host.port"] = "test_port" - envelope = exporter._point_to_envelope(point, "http.client.duration", resource, scope) + envelope = exporter._point_to_envelope(point, "http.client.duration", resource) self.assertEqual(envelope.data.base_data.properties['dependency/target'], "test_peer_name:test_port") # Success/Failure point.attributes["http.status_code"] = 500 - envelope = exporter._point_to_envelope(point, "http.client.duration", resource, scope) + envelope = exporter._point_to_envelope(point, "http.client.duration", resource) self.assertEqual(envelope.data.base_data.properties['Dependency.Success'], "False") @@ -323,7 +317,6 @@ def test_point_to_envelope_std_metric_server_duration(self): {"service.name": "testServiceName", "service.namespace": "testServiceNamespace", "service.instance.id": "testServiceInstanceId"}) - scope = InstrumentationScope("opentelemetry.instrumentation.flask") point=NumberDataPoint( attributes={ "http.status_code": 200, @@ -334,7 +327,7 @@ def test_point_to_envelope_std_metric_server_duration(self): time_unix_nano=1646865018558419457, value=15.0, ) - envelope = exporter._point_to_envelope(point, "http.server.duration", resource, scope) + envelope = exporter._point_to_envelope(point, "http.server.duration", resource) self.assertEqual(envelope.instrumentation_key, exporter._instrumentation_key) self.assertEqual(envelope.name, 'Microsoft.ApplicationInsights.Metric') self.assertEqual(envelope.time, ns_to_iso_str(point.time_unix_nano)) @@ -348,12 +341,11 @@ def test_point_to_envelope_std_metric_server_duration(self): self.assertIsNone(envelope.data.base_data.properties.get("custom_attr")) self.assertEqual(len(envelope.data.base_data.metrics), 1) self.assertEqual(envelope.data.base_data.metrics[0].name, "http.server.duration") - self.assertEqual(envelope.data.base_data.metrics[0].namespace, "opentelemetry.instrumentation.flask") self.assertEqual(envelope.data.base_data.metrics[0].value, 15.0) # Success/Failure point.attributes["http.status_code"] = 600 - envelope = exporter._point_to_envelope(point, "http.server.duration", resource, scope) + envelope = exporter._point_to_envelope(point, "http.server.duration", resource) self.assertEqual(envelope.data.base_data.properties['Request.Success'], "False") def test_point_to_envelope_std_metric_unsupported(self): @@ -362,7 +354,6 @@ def test_point_to_envelope_std_metric_unsupported(self): {"service.name": "testServiceName", "service.namespace": "testServiceNamespace", "service.instance.id": "testServiceInstanceId"}) - scope = InstrumentationScope("opentelemetry.instrumentation.flask") point=NumberDataPoint( attributes={ "http.status_code": 200, @@ -373,7 +364,7 @@ def test_point_to_envelope_std_metric_unsupported(self): time_unix_nano=1646865018558419457, value=15.0, ) - envelope = exporter._point_to_envelope(point, "http.server.request.size", resource, scope) + envelope = exporter._point_to_envelope(point, "http.server.request.size", resource) self.assertIsNone(envelope) diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_exporter.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_exporter.py index be9b648cee35..e9569c16740b 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_exporter.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/tests/statsbeat/test_exporter.py @@ -6,7 +6,6 @@ from unittest import mock from datetime import datetime -from opentelemetry.sdk.util.instrumentation import InstrumentationScope from opentelemetry.sdk.resources import Resource from opentelemetry.sdk.metrics.export import NumberDataPoint @@ -69,7 +68,6 @@ def test_init(self, collect_mock): def test_point_to_envelope(self): resource = Resource.create(attributes={"asd":"test_resource"}) - scope = InstrumentationScope("test_scope") point=NumberDataPoint( start_time_unix_nano=1646865018558419456, time_unix_nano=1646865018558419457, @@ -77,7 +75,7 @@ def test_point_to_envelope(self): attributes={}, ) for ot_name, sb_name in _STATSBEAT_METRIC_NAME_MAPPINGS.items(): - envelope = self._exporter._point_to_envelope(point, ot_name, resource, scope) + envelope = self._exporter._point_to_envelope(point, ot_name, resource) self.assertEqual(envelope.data.base_data.metrics[0].name, sb_name) def test_transmit_200_reach_ingestion(self):