diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md index 54e405fb5387..cda596fabf99 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/CHANGELOG.md @@ -13,6 +13,8 @@ ### Breaking Changes ### Bugs Fixed +- Add custom metric mapping for customer sdkstats metric names to preserve casing + ([#44855](https://github.com/Azure/azure-sdk-for-python/pull/44855)) - Fix customer SDK stats metrics to display drop code and retry code enum values without the prefix ([#44852](https://github.com/Azure/azure-sdk-for-python/pull/44852)) @@ -771,4 +773,4 @@ - Initial alpha release -# cSpell:enable +# cSpell:enable \ No newline at end of file diff --git a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py index cc8f19702a6d..11ec9db31f53 100644 --- a/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py +++ b/sdk/monitor/azure-monitor-opentelemetry-exporter/azure/monitor/opentelemetry/exporter/_constants.py @@ -183,10 +183,24 @@ class RetryCode(str, Enum, metaclass=CaseInsensitiveEnumMeta): RetryCodeType = Union[RetryCode, int] +# Customer SDK Stats metric names: (lowercase_otel_name, pascal_case_display_name) +_ITEM_SUCCESS_COUNT_NAME = ("item_success_count", "Item_Success_Count") +_ITEM_DROP_COUNT_NAME = ("item_dropped_count", "Item_Dropped_Count") +_ITEM_RETRY_COUNT_NAME = ("item_retry_count", "Item_Retry_Count") + +_CUSTOMER_SDKSTATS_METRIC_NAME_MAPPINGS = dict( + [ + _ITEM_SUCCESS_COUNT_NAME, + _ITEM_DROP_COUNT_NAME, + _ITEM_RETRY_COUNT_NAME, + ] +) + + class CustomerSdkStatsMetricName(str, Enum, metaclass=CaseInsensitiveEnumMeta): - ITEM_SUCCESS_COUNT = "Item_Success_Count" - ITEM_DROP_COUNT = "Item_Dropped_Count" - ITEM_RETRY_COUNT = "Item_Retry_Count" + ITEM_SUCCESS_COUNT = _ITEM_SUCCESS_COUNT_NAME[0] + ITEM_DROP_COUNT = _ITEM_DROP_COUNT_NAME[0] + ITEM_RETRY_COUNT = _ITEM_RETRY_COUNT_NAME[0] ## Map from Azure Monitor envelope base_types to TelemetryType 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 69ef653465d8..4a5bb1aa2f7d 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 @@ -39,6 +39,7 @@ _APPLICATIONINSIGHTS_METRICS_TO_LOGANALYTICS_ENABLED, _APPLICATIONINSIGHTS_METRIC_NAMESPACE_OPT_IN, _AUTOCOLLECTED_INSTRUMENT_NAMES, + _CUSTOMER_SDKSTATS_METRIC_NAME_MAPPINGS, _METRIC_ENVELOPE_NAME, _STATSBEAT_METRIC_NAME_MAPPINGS, ) @@ -167,6 +168,9 @@ def _point_to_envelope( final_metric_name = name if self._is_sdkstats and name in _STATSBEAT_METRIC_NAME_MAPPINGS: final_metric_name = _STATSBEAT_METRIC_NAME_MAPPINGS[name] + # Apply customer sdkstats metric name mapping if this is a customer sdkstats exporter + if self._is_customer_sdkstats and name in _CUSTOMER_SDKSTATS_METRIC_NAME_MAPPINGS: + final_metric_name = _CUSTOMER_SDKSTATS_METRIC_NAME_MAPPINGS[name] envelope = _convert_point_to_envelope(point, final_metric_name, resource, scope) # Note that Performance Counters are not counted as "Autocollected standard metrics"