Skip to content

Support http/json in otlptracehttp - #8273

Merged
MrAlias merged 25 commits into
open-telemetry:mainfrom
sqyang94:support-http-json-otlptracehttp
Aug 12, 2026
Merged

MrAlias merged 25 commits into
open-telemetry:mainfrom
sqyang94:support-http-json-otlptracehttp

Conversation

@sqyang94

Copy link
Copy Markdown
Contributor

Resolves #8150

My initial impression to this issue was to just add a new option like WithEncoding to switch between protobuf and json. But after realizing that users can use OTEL_EXPORTER_OTLP_[TRACES_]* environment variables to control the configuration and the OTLP specification has already defined OTEL_EXPORTER_OTLP_[*_]PROTOCOL to support grpc, http/protobuf and http/json, I decided to add a new option type Protocol to control the protocol/encoding.

Let me know if this is the intended usage of the OTLP protocol.

@linux-foundation-easycla

linux-foundation-easycla Bot commented Apr 28, 2026 •

Copy link
Copy Markdown

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov

codecov Bot commented Apr 29, 2026 •

Copy link
Copy Markdown

Codecov Report

โŒ Patch coverage is 86.98795% with 54 lines in your changes missing coverage. Please review.
โœ… Project coverage is 84.1%. Comparing base (b936798) to head (3b128cc).

Files with missing lines Patch % Lines
.../internal/otlpjson/export_trace_service_request.go 85.9% 22 Missing and 22 partials โš ๏ธ
exporters/otlp/otlptrace/otlptracehttp/client.go 69.6% 6 Missing and 4 partials โš ๏ธ
Additional details and impacted files

Impacted file tree graph

@@          Coverage Diff           @@
##            main   #8273    +/-   ##
======================================
  Coverage   84.0%   84.1%            
======================================
  Files        329     331     +2     
  Lines      26068   26468   +400     
======================================
+ Hits       21919   22267   +348     
- Misses      3768    3795    +27     
- Partials     381     406    +25     
Files with missing lines Coverage ฮ”
...ace/otlptracegrpc/internal/otlpconfig/envconfig.go 90.8% <100.0%> (+1.7%) โฌ†๏ธ
...trace/otlptracegrpc/internal/otlpconfig/options.go 94.6% <100.0%> (+0.5%) โฌ†๏ธ
...ace/otlptracehttp/internal/otlpconfig/envconfig.go 90.8% <100.0%> (+1.7%) โฌ†๏ธ
...trace/otlptracehttp/internal/otlpconfig/options.go 93.4% <100.0%> (+0.6%) โฌ†๏ธ
...internal/otlpjson/export_trace_service_response.go 100.0% <100.0%> (รธ)
exporters/otlp/otlptrace/otlptracehttp/options.go 100.0% <100.0%> (รธ)
exporters/otlp/otlptrace/otlptracehttp/client.go 83.4% <69.6%> (-1.4%) โฌ‡๏ธ
.../internal/otlpjson/export_trace_service_request.go 85.9% <85.9%> (รธ)

... and 1 file with indirect coverage changes

๐Ÿš€ New features to boost your workflow:
  • โ„๏ธ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@sqyang94 sqyang94 changed the title Support http/json in otlptracehttp Support http/json in otlptracehttp Apr 29, 2026

@MrAlias MrAlias 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.

This adds the expected http/json configuration path, but I donโ€™t think the wire behavior is correct yet.

The main issue is that the new JSON path is using generic protobuf JSON marshaling/unmarshaling rather than OTLP/JSONโ€™s mapping rules. That can make a spec-compliant collector reject trace exports, and it also makes the response path less forward-compatible than OTLP requires. The current tests mostly validate the new path against the repoโ€™s own mock collector, which uses the same protojson behavior and can hide these interoperability problems.

Assisted-by: Claude Opus 4.7
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
sqyang94 added 3 commits May 1, 2026 00:30
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
Assisted-by: Claude Opus 4.7

@MrAlias MrAlias 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.

The OTLP/JSON correctness issues I raised earlier look addressed in the current revision. I just have one remaining doc nit inline.

sqyang94 added 2 commits May 1, 2026 16:55
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>

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.

Pull request overview

Adds OTLP http/json payload support to otlptracehttp, configurable via a new public WithEncoding option and the standard OTEL_EXPORTER_OTLP_[TRACES_]PROTOCOL env vars. Internally a new generated Protocol config value drives request marshaling and response decoding, with custom JSON encoding/decoding for ExportTraceServiceRequest and protojson for ExportTraceServiceResponse.

Changes:

  • Add Encoding type + WithEncoding public option to otlptracehttp, and a generated Protocol config (with env var parsing) shared between the trace HTTP and gRPC exporters.
  • Add a new internal/otlpjson package implementing OTLP JSON Protobuf encoding for trace requests (custom structs) and responses (protojson).
  • Switch client.go to choose Content-Type, request marshaling, and response decoding based on cfg.Protocol, and update the mock collector + tests to cover JSON request/response paths.

Reviewed changes

Copilot reviewed 14 out of 22 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
internal/shared/otlp/otlptrace/otlpconfig/optiontypes.go.tmpl Adds Protocol type and `ProtocolGRPC
internal/shared/otlp/otlptrace/otlpconfig/options.go.tmpl Adds Protocol field, defaults in HTTP/gRPC configs, and WithProtocol split option.
internal/shared/otlp/otlptrace/otlpconfig/options_test.go.tmpl Adds protocol test cases for option and env-var configuration.
internal/shared/otlp/otlptrace/otlpconfig/envconfig.go.tmpl Adds WithEnvProtocol env reader and wires it into getOptionsFromEnv.
exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/{optiontypes,options,envconfig,options_test}.go Generated counterparts of the above templates.
exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/{optiontypes,options,envconfig,options_test}.go Generated counterparts for gRPC (mostly no-op at runtime).
exporters/otlp/otlptrace/otlptracehttp/options.go Adds public Encoding type and WithEncoding(Encoding) mapping to otlpconfig.WithProtocol.
exporters/otlp/otlptrace/otlptracehttp/client.go Switches Content-Type, request marshaling, and 2xx response decoding on cfg.Protocol.
exporters/otlp/otlptrace/otlptracehttp/doc.go Documents JSON payload support and protocol env vars.
exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_request.go New custom OTLP JSON encoder/decoder for trace requests.
exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_response.go protojson-based encoder/decoder for trace responses.
exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/*_test.go Unit tests for the new JSON encoding/decoding.
exporters/otlp/otlptrace/otlptracehttp/{client_test.go,mock_collector_test.go} E2E tests and mock collector updates for JSON request/response handling.
CHANGELOG.md Adds entry under Unreleased Added.
Files not reviewed (8)
  • exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/envconfig.go: Language not supported
  • exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options.go: Language not supported
  • exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/options_test.go: Language not supported
  • exporters/otlp/otlptrace/otlptracegrpc/internal/otlpconfig/optiontypes.go: Language not supported
  • exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/envconfig.go: Language not supported
  • exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options.go: Language not supported
  • exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/options_test.go: Language not supported
  • exporters/otlp/otlptrace/otlptracehttp/internal/otlpconfig/optiontypes.go: Language not supported

@pellared

Copy link
Copy Markdown
Member
exporters/otlp/otlptrace/otlptracehttp/internal/otlpjson/export_trace_service_request_test.go:291:1: File is not properly formatted (gofumpt)

MrAlias and others added 3 commits August 11, 2026 07:55
Modern Go tooling ignores canonical import path comments in module mode,
and the modernize linter now reports them as errors. Remove the comments
from the OTLP JSON package so the pull request passes lint.
@MrAlias
MrAlias merged commit 21de513 into open-telemetry:main Aug 12, 2026
35 checks passed
pellared added a commit that referenced this pull request Aug 25, 2026
This release is the last to support [Go 1.25].
The next release will require at least [Go 1.26].

### Added

- Support testing of [Go 1.27]. (#8811)
- Support `http/json` protocol in
`go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp`.
(#8273, #8775, #8831)
- Add `Hasher` struct and methods in
`go.opentelemetry.io/otel/attribute` to compute authoritative `Distinct`
hashes incrementally for attribute filtering and deduplication. (#8598)

### Changed

- Lazily evaluate filtered and dropped attributes on measurement hot
paths in `go.opentelemetry.io/otel/sdk/metric` to avoid unnecessary
attribute set allocations. (#8598)
- Add `ErrExporterShutdown` to `go.opentelemetry.io/otel/sdk/log` and
return it from the
`go.opentelemetry.io/otel/exporters/stdout/stdoutlog`,
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc`, and
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp` exporters
when `Export` is called after `Shutdown`. (#8773)
- Clarify in `go.opentelemetry.io/otel/log` that calling
`Logger.Enabled` is optional and that cached results can become stale.
(#8764)

### Fixed

- Export dropped attribute counts in OTLP log records from
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc` and
`go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp`. (#8829)
- Name span events created from OpenTracing logs after the `event` log
field, falling back to `log`, instead of always using an empty name in
`go.opentelemetry.io/otel/bridge/opentracing`. (#8648)
- Count exception attributes omitted due to the attribute count limit as
dropped in `go.opentelemetry.io/otel/sdk/log`. (#8796)
- Prevent log record and instrumentation scope attributes with empty
keys from reaching processors and exporters in
`go.opentelemetry.io/otel/sdk/log`. (#8797)
- Fix a data race when span attributes are read concurrently in
`go.opentelemetry.io/otel/sdk/trace`. (#8706)
- Prevent a panic in `(*Set).Filter` when called on a nil receiver in
`go.opentelemetry.io/otel/attribute`. (#8792)
- The simple span and log processors record
`otel.sdk.processor.{span,log}.processed` when the record is submitted
to the exporter instead of after the export completes, and no longer set
`error.type` from the export outcome, in
`go.opentelemetry.io/otel/sdk/trace` and
`go.opentelemetry.io/otel/sdk/log`. (#8705)
- Prevent `Resource.MarshalLog` from panicking on nil resources in
`go.opentelemetry.io/otel/sdk/resource`. (#8758)

[Go 1.27]: https://go.dev/doc/go1.27
[Go 1.26]: https://go.dev/doc/go1.26
[Go 1.25]: https://go.dev/doc/go1.25
@pellared pellared added this to the v1.46.0 milestone Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support http/json in otlptracehttp

5 participants