Fix OTLP JSON deserialization of numeric histogram bucketCounts#16376
Merged
Fix OTLP JSON deserialization of numeric histogram bucketCounts#16376
Conversation
Contributor
|
🚀 Dogfood this PR with:
curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16376Or
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16376" |
Contributor
There was a problem hiding this comment.
Pull request overview
Improves OTLP JSON metrics deserialization robustness in Aspire (Dashboard + CLI shared OTLP serializer) by accepting histogram bucketCounts emitted as JSON numbers (a common exporter deviation from protojson’s uint64-as-string requirement), preventing JsonException failures when ingesting metrics.
Changes:
- Added
StringArrayFromNumbersConverterto deserializestring[]from JSON arrays containing either string or number tokens. - Applied the converter to histogram
bucketCountsfields in the shared OTLP metrics JSON model. - Added an integration test covering numeric
bucketCountsingestion and repository persistence.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| tests/Aspire.Dashboard.Tests/Integration/OtlpHttpJsonTests.cs | Adds an integration test and sample payload to validate numeric bucketCounts are accepted and stored correctly. |
| src/Shared/Otlp/Serialization/StringArrayFromNumbersConverter.cs | Introduces a converter that reads string-or-number JSON array elements into string[]. |
| src/Shared/Otlp/Serialization/OtlpMetricsJson.cs | Annotates histogram bucket count properties to use the new converter. |
| src/Aspire.Dashboard/Aspire.Dashboard.csproj | Links the new shared converter source file into the Dashboard build. |
| src/Aspire.Cli/Aspire.Cli.csproj | Links the new shared converter source file into the CLI build. |
Some OTLP exporters send uint64 histogram bucket counts as JSON numbers instead of strings. The protojson spec requires string encoding for uint64 fields, but small values are often sent as bare numbers. Change BucketCounts from string[] to ulong[] with JsonNumberHandling (WriteAsString | AllowReadingFromString), matching the pattern used by Count, TimeUnixNano, and other uint64 properties. This lets System.Text.Json handle both string and number tokens natively without a custom converter. Also simplifies OtlpJsonProtobufConverter (removes ulong.Parse calls) and TelemetryExportService (removes ToString conversion).
a5edf04 to
44b5bdd
Compare
eerhardt
reviewed
Apr 22, 2026
eerhardt
approved these changes
Apr 22, 2026
Contributor
|
🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit View recordings
📹 Recordings uploaded automatically from CI run #24782516441 |
This was referenced Apr 23, 2026
Closed
Closed
Closed
Closed
Closed
Closed
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
Some OTLP exporters (e.g. VS Code Copilot Chat) send histogram
bucketCountsas JSON numbers ([0, 2, 0, ...]) instead of strings (["0", "2", "0", ...]). While the protojson spec requires string encoding foruint64fields, many exporters emit small values as bare numbers. This causes aJsonExceptionin the Dashboard:Changes
The fix changes
BucketCountsfromstring[]toulong[]with[JsonNumberHandling(WriteAsString | AllowReadingFromString)], matching the pattern already used byCount,TimeUnixNano, and otheruint64properties in the same file. This letsSystem.Text.Jsonhandle both string and number tokens natively.OtlpMetricsJson.cs—BucketCountsonOtlpHistogramDataPointJsonandOtlpExponentialHistogramBucketsJsonchanged fromstring[]toulong[]withJsonNumberHandlingattribute.OtlpJsonProtobufConverter.cs— removedulong.Parse()calls, values are now added directly.TelemetryExportService.cs— removed.Select(v => v.ToString(...)).ToArray(), assignsulong[]directly.OtlpHttpJsonTests.cs— addedCallService_Metrics_NumericBucketCounts_Successintegration test that posts metrics JSON with numeric bucket counts and asserts histogram data (bounds + counts) is deserialized correctly end-to-end.Checklist