Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,7 +664,7 @@ contact [[email protected]](mailto:[email protected]) with any additio

<!-- LINKS -->
[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/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -95,7 +94,6 @@ def export(
point,
metric.name,
resource_metric.resource,
scope_metric.scope
)
if envelope is not None:
envelopes.append(envelope)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand All @@ -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_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -18,13 +17,12 @@ 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]
return super()._point_to_envelope(
point,
name,
resource,
scope,

)
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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))
Expand All @@ -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",
Expand All @@ -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))
Expand All @@ -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)

Expand All @@ -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,
Expand All @@ -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))
Expand All @@ -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")


Expand All @@ -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,
Expand All @@ -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))
Expand All @@ -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):
Expand All @@ -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,
Expand All @@ -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)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -69,15 +68,14 @@ 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,
value=10,
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):
Expand Down