Skip to content

Fix OTLP JSON deserialization of numeric histogram bucketCounts#16376

Merged
JamesNK merged 1 commit intomainfrom
fix/otlp-numeric-bucket-counts
Apr 22, 2026
Merged

Fix OTLP JSON deserialization of numeric histogram bucketCounts#16376
JamesNK merged 1 commit intomainfrom
fix/otlp-numeric-bucket-counts

Conversation

@JamesNK
Copy link
Copy Markdown
Member

@JamesNK JamesNK commented Apr 22, 2026

Description

Some OTLP exporters (e.g. VS Code Copilot Chat) send histogram bucketCounts as JSON numbers ([0, 2, 0, ...]) instead of strings (["0", "2", "0", ...]). While the protojson spec requires string encoding for uint64 fields, many exporters emit small values as bare numbers. This causes a JsonException in the Dashboard:

The JSON value could not be converted to System.String.
Path: $.resourceMetrics[0].scopeMetrics[0].metrics[2].histogram.dataPoints[0].bucketCounts[0]

Changes

The fix changes BucketCounts from string[] to ulong[] with [JsonNumberHandling(WriteAsString | AllowReadingFromString)], matching the pattern already used by Count, TimeUnixNano, and other uint64 properties in the same file. This lets System.Text.Json handle both string and number tokens natively.

  • OtlpMetricsJson.csBucketCounts on OtlpHistogramDataPointJson and OtlpExponentialHistogramBucketsJson changed from string[] to ulong[] with JsonNumberHandling attribute.
  • OtlpJsonProtobufConverter.cs — removed ulong.Parse() calls, values are now added directly.
  • TelemetryExportService.cs — removed .Select(v => v.ToString(...)).ToArray(), assigns ulong[] directly.
  • OtlpHttpJsonTests.cs — added CallService_Metrics_NumericBucketCounts_Success integration test that posts metrics JSON with numeric bucket counts and asserts histogram data (bounds + counts) is deserialized correctly end-to-end.

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
    • No
  • Does the change require an update in our Aspire docs?
    • Yes
    • No

Copilot AI review requested due to automatic review settings April 22, 2026 13:54
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Apr 22, 2026

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 16376

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/microsoft/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 16376"

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 StringArrayFromNumbersConverter to deserialize string[] from JSON arrays containing either string or number tokens.
  • Applied the converter to histogram bucketCounts fields in the shared OTLP metrics JSON model.
  • Added an integration test covering numeric bucketCounts ingestion 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).
@JamesNK JamesNK force-pushed the fix/otlp-numeric-bucket-counts branch from a5edf04 to 44b5bdd Compare April 22, 2026 13:59
@JamesNK JamesNK changed the title Handle numeric bucketCounts in OTLP JSON metrics deserialization Fix OTLP JSON deserialization of numeric histogram bucketCounts Apr 22, 2026
Comment thread tests/Aspire.Dashboard.Tests/Integration/OtlpHttpJsonTests.cs
@JamesNK JamesNK enabled auto-merge (squash) April 22, 2026 14:41
@JamesNK JamesNK merged commit f79d041 into main Apr 22, 2026
562 of 565 checks passed
@github-actions github-actions Bot added this to the 13.3 milestone Apr 22, 2026
@github-actions
Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings — 72 recordings uploaded (commit 44b5bdd)

View recordings
Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
Banner_NotDisplayedWithNoLogoFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunEmptyAppHostProject ▶️ View Recording
CreateAndRunJavaEmptyAppHostProject ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptEmptyAppHostProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateJavaAppHostWithViteApp ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DashboardRunWithOtelTracesReturnsNoTraces ▶️ View Recording
DeployK8sBasicApiService ▶️ View Recording
DeployK8sWithGarnet ▶️ View Recording
DeployK8sWithMongoDB ▶️ View Recording
DeployK8sWithMySql ▶️ View Recording
DeployK8sWithPostgres ▶️ View Recording
DeployK8sWithRabbitMQ ▶️ View Recording
DeployK8sWithRedis ▶️ View Recording
DeployK8sWithSqlServer ▶️ View Recording
DeployK8sWithValkey ▶️ View Recording
DeployTypeScriptAppToKubernetes ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DetachFormatJsonProducesValidJsonWhenRestartingExistingInstance ▶️ View Recording
DoListStepsShowsPipelineSteps ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InitTypeScriptAppHost_AugmentsExistingViteRepoAtRoot ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LegacySettingsMigration_AdjustsRelativeAppHostPath ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
OtelLogsReturnsStructuredLogsFromStarterApp ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithConfigureEnvFileUpdatesEnvOutput ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
PublishWithoutOutputPathUsesAppHostDirectoryDefault ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RestoreRefreshesGeneratedSdkAfterAddingIntegration ▶️ View Recording
RestoreSupportsConfigOnlyHelperPackageAndCrossPackageTypes ▶️ View Recording
RunFromParentDirectory_UsesExistingConfigNearAppHost ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StartAndWaitForTypeScriptSqlServerAppHostWithNativeAssets ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
UnAwaitedChainsCompileWithAutoResolvePromises ▶️ View Recording

📹 Recordings uploaded automatically from CI run #24782516441

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants