Skip to content

[Exporters] Encode maps and arrays as JSON - #7694

Merged
martincostello merged 25 commits into
open-telemetry:mainfrom
martincostello:otel-spec-5149-prometheus
Oct 23, 2026
Merged

martincostello merged 25 commits into
open-telemetry:mainfrom
martincostello:otel-spec-5149-prometheus

Conversation

@martincostello

@martincostello martincostello commented Aug 25, 2026 •

Copy link
Copy Markdown
Member

Changes

/cc @pellared

Merge requirement checklist

  • CONTRIBUTING guidelines followed (license requirements, nullable enabled, static analysis, etc.)
  • Unit tests added/updated
  • Appropriate CHANGELOG.md files updated for non-trivial changes
  • Changes in public API reviewed (if applicable)

- Format `byte[]` values for non-OTLP exporters as Base64-encoded strings.
- Format arrays and map values in the Prometheus exporter as JSON.
@github-actions github-actions Bot added pkg:OpenTelemetry.Exporter.Console Issues related to OpenTelemetry.Exporter.Console NuGet package pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package pkg:OpenTelemetry.Exporter.Zipkin Issues related to OpenTelemetry.Exporter.Zipkin NuGet package labels Aug 25, 2026
@codecov

codecov Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.92308% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 90.50%. Comparing base (de98f62) to head (1eb753b).
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...l/Shared/Serialization/PrometheusAnyValueWriter.cs 95.91% 0 Missing and 2 partials ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #7694      +/-   ##
==========================================
- Coverage   90.53%   90.50%   -0.03%     
==========================================
  Files         378      379       +1     
  Lines       22144    22201      +57     
  Branches     4108     4118      +10     
==========================================
+ Hits        20048    20094      +46     
- Misses       1518     1524       +6     
- Partials      578      583       +5     
Flag Coverage Δ
unittests-PowerShellScripts 87.43% <ø> (ø)
unittests-Project-Experimental 90.56% <96.92%> (-0.04%) ⬇️
unittests-Project-Stable 90.52% <96.92%> (-0.06%) ⬇️
unittests-Solution 90.58% <96.92%> (+0.05%) ⬆️
unittests-UnstableCoreLibraries-Experimental 42.54% <96.87%> (+0.21%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...r/Internal/Shared/PrometheusExporterEventSource.cs 100.00% <100.00%> (ø)
...ernal/Shared/Serialization/TextFormatSerializer.cs 96.42% <100.00%> (+0.02%) ⬆️
....Exporter.Zipkin/Implementation/ZipkinTagWriter.cs 65.71% <100.00%> (+1.00%) ⬆️
...l/Shared/Serialization/PrometheusAnyValueWriter.cs 95.91% <95.91%> (ø)

... and 4 files with indirect coverage changes

Add missing test coverage.
@martincostello martincostello added the keep-open Prevents issues and pull requests being closed as stale label Aug 25, 2026

@pellared pellared left a comment •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@martincostello, thanks a lot for the PR!
Only the changes in OpenTelemetry.Exporter.Zipkin seem to be against the spec and may break some users.

@opentelemetry-pr-dashboard

opentelemetry-pr-dashboard Bot commented Sep 2, 2026 •

Copy link
Copy Markdown

Pull request dashboard status

Merged · refreshed 2026-10-27 15:16 UTC

Status above doesn't look right?
  • Anything look wrong? Report it with what you expected; it helps us improve the dashboard.

Revert Zipkin to previous behaviour for backwards-compatibility.
@martincostello
martincostello requested review from pellared and a balanced review from Copilot and removed request for pellared September 7, 2026 08:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🟡 Changes recommended

Some supported map forms and nested or non-finite array values are serialized incorrectly.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Pull request overview

Updates non-OTLP exporters to encode byte arrays as Base64 and Prometheus arrays/maps as JSON.

Changes:

  • Adds shared Base64 byte-array serialization, preserving Zipkin behavior.
  • Adds Prometheus JSON serialization for arrays and maps.
  • Adds tests, diagnostics, dependencies, and changelog entries.
File summaries
File Description
test/OpenTelemetry.Exporter.Zipkin.Tests/Implementation/ZipkinActivityConversionTests.cs Verifies Zipkin byte-array compatibility.
test/OpenTelemetry.Exporter.Prometheus.HttpListener.Tests/PrometheusSerializerTests.cs Tests Prometheus structured values.
test/OpenTelemetry.Exporter.Console.Tests/ConsoleKvListAttributeTests.cs Tests Base64 console output.
src/Shared/TagWriter/JsonStringArrayTagWriter.cs Adds shared Base64 encoding.
src/OpenTelemetry.Exporter.Zipkin/Implementation/ZipkinTagWriter.cs Retains Zipkin’s JSON-array behavior.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/OpenTelemetry.Exporter.Prometheus.HttpListener.csproj Links serialization support.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializer.cs Routes structured labels through JSON encoding.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/PrometheusAnyValueWriter.cs Implements Prometheus AnyValue JSON serialization.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/PrometheusExporterEventSource.cs Adds unsupported-value diagnostics.
src/OpenTelemetry.Exporter.Prometheus.HttpListener/CHANGELOG.md Documents HttpListener changes.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/OpenTelemetry.Exporter.Prometheus.AspNetCore.csproj Links shared tag writers.
src/OpenTelemetry.Exporter.Prometheus.AspNetCore/CHANGELOG.md Documents ASP.NET Core changes.
src/OpenTelemetry.Exporter.Console/CHANGELOG.md Documents console encoding changes.
Review details

Suppressed comments (1)

src/OpenTelemetry.Exporter.Prometheus.HttpListener/Internal/Shared/Serialization/TextFormatSerializer.cs:1417

  • The cached/scope-label path has the same incomplete map detection: for example, Dictionary<string, string> is not convertible to IEnumerable<KeyValuePair<string, object?>>, so it remains a .NET type name instead of JSON. Match every map shape supported by TagWriter.
        byte[] byteArrayValue => Convert.ToBase64String(byteArrayValue),
        Array or IEnumerable<KeyValuePair<string, object?>> => PrometheusAnyValueWriter.Instance.ToLabelValueString(key, labelValue),
  • Files reviewed: 13/13 changed files
  • Comments generated: 6
  • Review effort level: Balanced

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

- Support nested arrays and maps.
- Handle other map shapes.
- Handle `NaN` and infinite numbers as JSON strings.
- Fix-up CHANGELOG entries.
Update test for new format.
@github-actions github-actions Bot added the pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package label Sep 10, 2026
@martincostello martincostello added the spec-compliance Issues related to compliance with the OpenTelemetry Specification label Oct 8, 2026
This was referenced Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

infra Infra work - CI/CD, code coverage, linters pkg:OpenTelemetry.Exporter.Console Issues related to OpenTelemetry.Exporter.Console NuGet package pkg:OpenTelemetry.Exporter.OpenTelemetryProtocol Issues related to OpenTelemetry.Exporter.OpenTelemetryProtocol NuGet package pkg:OpenTelemetry.Exporter.Prometheus.AspNetCore Issues related to OpenTelemetry.Exporter.Prometheus.AspNetCore NuGet package pkg:OpenTelemetry.Exporter.Prometheus.HttpListener Issues related to OpenTelemetry.Exporter.Prometheus.HttpListener NuGet package pkg:OpenTelemetry.Exporter.Zipkin Issues related to OpenTelemetry.Exporter.Zipkin NuGet package pkg:OpenTelemetry Issues related to OpenTelemetry NuGet package spec-compliance Issues related to compliance with the OpenTelemetry Specification

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants