Skip to content

Support http/json in otlptracehttp#8273

Open
sqyang94 wants to merge 14 commits intoopen-telemetry:mainfrom
sqyang94:support-http-json-otlptracehttp
Open

Support http/json in otlptracehttp#8273
sqyang94 wants to merge 14 commits intoopen-telemetry:mainfrom
sqyang94:support-http-json-otlptracehttp

Conversation

@sqyang94
Copy link
Copy Markdown

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
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Apr 28, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

@codecov
Copy link
Copy Markdown

codecov Bot commented Apr 29, 2026

Codecov Report

❌ Patch coverage is 86.98795% with 54 lines in your changes missing coverage. Please review.
✅ Project coverage is 83.0%. Comparing base (b4c3b6a) to head (475c114).

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   82.9%   83.0%            
======================================
  Files        314     316     +2     
  Lines      24985   25385   +400     
======================================
+ Hits       20729   21081   +352     
- Misses      3882    3907    +25     
- Partials     374     397    +23     
Files with missing lines Coverage Δ
...ace/otlptracegrpc/internal/otlpconfig/envconfig.go 90.3% <100.0%> (+1.9%) ⬆️
...trace/otlptracegrpc/internal/otlpconfig/options.go 94.6% <100.0%> (+0.5%) ⬆️
...ace/otlptracehttp/internal/otlpconfig/envconfig.go 90.3% <100.0%> (+1.9%) ⬆️
...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 79.6% <69.6%> (-1.1%) ⬇️
.../internal/otlpjson/export_trace_service_request.go 85.9% <85.9%> (ø)

... and 3 files 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
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

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.

Comment thread exporters/otlp/otlptrace/otlptracehttp/client.go Outdated
Comment thread exporters/otlp/otlptrace/otlptracehttp/client.go Outdated
Comment thread exporters/otlp/otlptrace/otlptracehttp/mock_collector_test.go Outdated
Comment thread exporters/otlp/otlptrace/otlptracehttp/client_test.go
Assisted-by: Claude Opus 4.7
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
}

// WithProtocol tells the driver to use a specific protocol for the request payload.
func WithProtocol(protocol Protocol) Option {
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Now I'm leaning towards WithEncoding in otlptracehttp as opposed to WithProtocol. It feels a bit weird to call it WithProtocol but only provide two options, as grpc definitely doesn't make sense to be here.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Renamed in cb4aac9

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
Copy link
Copy Markdown
Contributor

@MrAlias MrAlias left a comment

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.

Comment thread exporters/otlp/otlptrace/otlptracehttp/doc.go
sqyang94 added 2 commits May 1, 2026 16:55
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
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

2 participants