diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index e5a5fc06c000..289cd2b1032f 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -6,6 +6,8 @@ - Add validation logic to ApplicationInsightsSampler ([#26546](https://github.com/Azure/azure-sdk-for-python/pull/26546)) +- Change default temporality of metrics to follow OTLP + ([#26546](https://github.com/Azure/azure-sdk-for-python/pull/26546)) ### Breaking Changes 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 366bac4cadc9..dcd051bd4567 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 @@ -4,7 +4,16 @@ from typing import Optional, Any +from opentelemetry.sdk.metrics import ( + Counter, + Histogram, + ObservableCounter, + ObservableGauge, + ObservableUpDownCounter, + UpDownCounter, +) from opentelemetry.sdk.metrics.export import ( + AggregationTemporality, DataPointT, HistogramDataPoint, MetricExporter, @@ -32,6 +41,16 @@ __all__ = ["AzureMonitorMetricExporter"] +APPLICATION_INSIGHTS_METRIC_TEMPORALITIES = { + Counter: AggregationTemporality.DELTA, + Histogram: AggregationTemporality.DELTA, + ObservableCounter: AggregationTemporality.DELTA, + ObservableGauge: AggregationTemporality.CUMULATIVE, + ObservableUpDownCounter: AggregationTemporality.CUMULATIVE, + UpDownCounter: AggregationTemporality.CUMULATIVE, +} + + class AzureMonitorMetricExporter(BaseExporter, MetricExporter): """Azure Monitor Metric exporter for OpenTelemetry.""" @@ -39,7 +58,7 @@ def __init__(self, **kwargs: Any) -> None: BaseExporter.__init__(self, **kwargs) MetricExporter.__init__( self, - preferred_temporality=kwargs.get("preferred_temporality"), + preferred_temporality=APPLICATION_INSIGHTS_METRIC_TEMPORALITIES, preferred_aggregation=kwargs.get("preferred_aggregation"), )