Skip to content

"Metric Namespace" not working for metrics sent to Azure Monitor #41139

Description

@fyayc-bue
  • monitor.opentelemetry.exporter:
  • 1.0.0.b36:
  • all:
  • all:

Describe the bug
No way to define a custom "Metric Namespace" different from 'azure.applicationinsights' when using the
azure.monitor.opentelemetry.exporter.AzureMonitorMetricExporter from azure-monitor-opentelemetry-exporter==1.0.0.b36.

To Reproduce
Steps to reproduce the behavior:

  1. Set up telemetry to Azure Monitor
  2. Run the testcode below to publish one value (1.1)
  3. Verify transmission and storage in Azure Monitor. Metric namespace 'azure.applicationinsights' contains your meter and the value 1.1.
  4. Provide a namespace='xyz' to your telemetry setup (see code)
  5. Publish a second value using the configuration with namespace='xyz' (1.2)
  6. Check transmission and storage in Azure Monitor. Metric Namespace 'azure.applicationinsights' still contains three entries. ![Image]Log-based metrics, Application Insights standard metrics, azure.applicationinsights instead of 4 including the new namespace 'xyz'.

Expected behavior
azure-monitor-opentelemetry-exporter sends the namespace and Azure Monitor respects this.
The Azure Monitor allows for selection of namespace 'xyz' when provided.

Screenshots
Image

Additional context

Code to reproduce the issue:

import time

from opentelemetry.sdk.metrics.export import PeriodicExportingMetricReader
from opentelemetry.sdk.metrics import MeterProvider
from opentelemetry.sdk.resources import Resource

from azure.monitor.opentelemetry.exporter import AzureMonitorMetricExporter

APPLICATIONINSIGHTS_CONNECTION_STRING = "InstrumentationKey=fb2...380;IngestionEndpoint=https://germanywestcentral-1.in.applicationinsights.azure.com/;LiveEndpoint=https://germanywestcentral.livediagnostics.monitor.azure.com/;ApplicationId=00d...5b"

namespace = ""
# namespace = "xyz"

if len(namespace) == 0:
    telemetry = AzureMonitorMetricExporter.from_connection_string(
        APPLICATIONINSIGHTS_CONNECTION_STRING,
    )
else:
    telemetry = AzureMonitorMetricExporter.from_connection_string(
        APPLICATIONINSIGHTS_CONNECTION_STRING,
        namespace=namespace + ".c.ns",
    )

reader = PeriodicExportingMetricReader(telemetry)

resource = Resource(
    attributes={
        "service.namespace": "svc.ns",
        "metric.namespace": "metric.ns",
        "service.name": f"svc.name"}
)

if len(namespace) == 0:
    meter_provider = MeterProvider(metric_readers=[reader])
    value = 1.1
else:
    meter_provider = MeterProvider(metric_readers=[reader], resource=resource)
    value = 1.2

telemeter = meter_provider.get_meter(f"sample.meter" + namespace)
tm = telemeter.create_gauge("sample.gauge" + namespace)

print(f"Sending value {value} {namespace if len(namespace) > 0 else ''}")
tm.set(value)
telemetry.force_flush()

telemetry.shutdown(1000)
print("Done")

Metadata

Metadata

Assignees

Labels

ClientThis issue points to a problem in the data-plane of the library.MonitorMonitor, Monitor Ingestion, Monitor Querycustomer-reportedIssues that are reported by GitHub users external to the Azure organization.needs-team-attentionWorkflow: This issue needs attention from Azure service team or SDK teamquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as that

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions