[AzureMonitorAutoConfigure] Add customer-facing SDKStats metrics (Item_Success_Count, Item_Dropped_Count, Item_Retry_Count)#48077
Open
rajkumar-rangaraj wants to merge 10 commits intomainfrom
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
Adds customer-facing “SDKStats” metric telemetry (success/drop/retry item counts) to the Azure Monitor OpenTelemetry autoconfigure exporter, along with unit tests and a manual sample for validation.
Changes:
- Introduces
CustomerSdkStatsaccumulator + telemetry type/exception categorization + pipeline listener to record per-type success/drop/retry counts. - Plumbs per-batch item-count metadata through
TelemetryItemExporter→TelemetryPipeline/Request, and addssendWithoutTracking()for exporting SDKStats metrics without recursion. - Adds unit tests for the new components plus a long-running sample + manual run guide.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 14 comments.
Show a summary per file
| File | Description |
|---|---|
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStats.java | New thread-safe counters + collectAndReset() producing Metric TelemetryItems. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsExceptionCategory.java | New exception categorization + timeout detection for retry dimensions. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsTelemetryType.java | Maps TelemetryItem.getName() to SDKStats telemetry_type dimension values. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsTelemetryPipelineListener.java | Observes pipeline responses/exceptions and increments the accumulator. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/pipeline/TelemetryItemExporter.java | Computes per-batch item-count metadata + adds sendWithoutTracking(). |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/pipeline/TelemetryPipeline.java | Adds overload to pass item-count metadata into requests. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/pipeline/TelemetryPipelineRequest.java | Stores item-count metadata maps and exposes getters. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/pipeline/TelemetryPipelineResponse.java | Makes constructor public for test construction. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/utils/AzureMonitorHelper.java | Wires CustomerSdkStatsTelemetryPipelineListener into the exporter listener chain. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/main/java/com/azure/monitor/opentelemetry/autoconfigure/AzureMonitorExporterBuilder.java | Creates/starts periodic export of SDKStats metrics (env-var configurable). |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsTest.java | Unit tests for accumulation/reset/concurrency. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsExceptionCategoryTest.java | Unit tests for exception categorization/timeout detection. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsTelemetryTypeTest.java | Unit tests for telemetry type mapping and null/unknown handling. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/test/java/com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsTelemetryPipelineListenerTest.java | Unit tests for response/exception classification + reason phrases. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/samples/java/com/azure/monitor/opentelemetry/autoconfigure/SimpleWebAppSample.java | Manual sample app + mock ingestion server to validate metric emission. |
| sdk/monitor/azure-monitor-opentelemetry-autoconfigure/src/samples/java/com/azure/monitor/opentelemetry/autoconfigure/SimpleWebAppSample-README.md | Step-by-step manual guide for the sample. |
...src/main/java/com/azure/monitor/opentelemetry/autoconfigure/AzureMonitorExporterBuilder.java
Show resolved
Hide resolved
...src/main/java/com/azure/monitor/opentelemetry/autoconfigure/AzureMonitorExporterBuilder.java
Show resolved
Hide resolved
...src/main/java/com/azure/monitor/opentelemetry/autoconfigure/AzureMonitorExporterBuilder.java
Outdated
Show resolved
Hide resolved
...a/com/azure/monitor/opentelemetry/autoconfigure/implementation/utils/AzureMonitorHelper.java
Outdated
Show resolved
Hide resolved
...emetry/autoconfigure/implementation/statsbeat/CustomerSdkStatsTelemetryPipelineListener.java
Outdated
Show resolved
Hide resolved
...re/monitor/opentelemetry/autoconfigure/implementation/pipeline/TelemetryPipelineRequest.java
Show resolved
Hide resolved
...igure/src/samples/java/com/azure/monitor/opentelemetry/autoconfigure/SimpleWebAppSample.java
Outdated
Show resolved
Hide resolved
.../src/samples/java/com/azure/monitor/opentelemetry/autoconfigure/SimpleWebAppSample-README.md
Show resolved
Hide resolved
...com/azure/monitor/opentelemetry/autoconfigure/implementation/statsbeat/CustomerSdkStats.java
Outdated
Show resolved
Hide resolved
...azure/monitor/opentelemetry/autoconfigure/implementation/pipeline/TelemetryItemExporter.java
Outdated
Show resolved
Hide resolved
…/Azure/azure-sdk-for-java into rajrang/exporterCustomerSdkStats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
PR: Add customer-facing SDKStats metrics (Item_Success_Count, Item_Dropped_Count, Item_Retry_Count)
Implements customer-facing SDKStats per spec. The exporter now tracks per-telemetry-type success, drop, and retry counts and periodically exports them as
MetricTelemetryItems through the existing pipeline to the customer's own Application Insights resource.New files
Production
CustomerSdkStats.javaConcurrentHashMap<Key, AtomicLong>) for three counter families:successCounts,droppedCounts,retryCounts.collectAndReset()atomically snapshots and clears all counters, returning a list ofTelemetryItemmetrics with the correct dimensions (computeType,language,version,telemetry_type,telemetry_success,drop.code/drop.reason,retry.code/retry.reason). Static factorycreate(version)auto-detects the resource provider.CustomerSdkStatsTelemetryType.javaTelemetryItem.getName()→ spec dimension strings:Request→REQUEST,RemoteDependency→DEPENDENCY,Message→TRACE,Exception→EXCEPTION,Metric→CUSTOM_METRIC,Event→CUSTOM_EVENT,PageView→PAGE_VIEW,Availability→AVAILABILITY. Returnsnullfor internal items (e.g.Statsbeat) to skip counting.CustomerSdkStatsExceptionCategory.javadrop.reason/retry.reason:"Timeout exception","Network exception","Storage exception","Client exception". Traverses the cause chain (depth ≤ 10). Also providesisTimeout()to choose betweenCLIENT_TIMEOUTandCLIENT_EXCEPTIONretry codes.CustomerSdkStatsTelemetryPipelineListener.javaTelemetryPipelineListenerthat routes pipeline responses to the accumulator: 200→success, retryable (401/403/408/429/500/502/503/504)→retry, redirect (307/308)→skip, all others→drop.onExceptioncategorizes the throwable and records a retry. IncludesgetReasonPhraseForStatusCode()for common HTTP status codes.Tests
CustomerSdkStatsTest.javaCustomerSdkStatsTelemetryTypeTest.javaCustomerSdkStatsExceptionCategoryTest.javaCustomerSdkStatsTelemetryPipelineListenerTest.javaSample
SimpleWebAppSample.javasuccess/drop/retry). In drop/retry modes, a built-in mock ingestion server on port 9090 returns the configured error status and prints all gunzipped payloads to the console, tagged[SDKStats]when applicable.SimpleWebAppSample-README.mdModified files
TelemetryItemExporter.javacomputeItemCountMetadata()to compute per-type item counts (with success/failure split for REQUEST/DEPENDENCY) before serialization. AddedsendWithoutTracking()to send items without triggering recursive customer SDKStats counting. UpdatedinternalSendByBatch()to pass item count maps to the pipeline.TelemetryPipelineRequest.javaitemCountsByType,successItemCountsByType,failureItemCountsByTypefields + overloaded public constructor + getters. The original constructor delegates with empty maps.TelemetryPipelineResponse.javapublic(was package-private) for test access.TelemetryPipeline.javasend()accepting item count maps; originalsend()delegates with empty maps. Passes maps intoTelemetryPipelineRequest.AzureMonitorHelper.javacreateTelemetryItemExporter()now acceptsCustomerSdkStats, creates aCustomerSdkStatsTelemetryPipelineListener, and wires it into the composite listener chain (alongsideDiagnosticTelemetryPipelineListenerandLocalStorageTelemetryPipelineListener).AzureMonitorExporterBuilder.javaSDKSTATS_DISABLED_ENV_VAR,SDKSTATS_EXPORT_INTERVAL_ENV_VARconstants. AddedcreateCustomerSdkStats()andstartCustomerSdkStats()with aScheduledExecutorService(daemon thread, default 900s interval) that callscollectAndReset()andsendWithoutTracking().Configuration
APPLICATIONINSIGHTS_SDKSTATS_DISABLEDfalsetrueto disable customer SDKStats entirely.APPLICATIONINSIGHTS_SDKSTATS_EXPORT_INTERVAL900(15 min)Metric details
Item_Success_CountcomputeType,language,version,telemetry_typeItem_Dropped_CountcomputeType,language,version,telemetry_type,drop.code,drop.reason,telemetry_successItem_Retry_CountcomputeType,language,version,telemetry_type,retry.code,retry.reasonValidation
spotlessApplycleanItem_Success_Countvisible in Azure MonitorcustomMetricstable with correct dimensionsItem_Dropped_Countvisible in mock server console withdrop.code=400,drop.reason="Bad request", per-type/per-success breakdownAll SDK Contribution checklist:
General Guidelines and Best Practices
Testing Guidelines