Repository navigation
Support http/json in otlptracehttp - #8273
Conversation
Codecov Reportโ Patch coverage is Additional details and impacted files@@ 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
๐ New features to boost your workflow:
|
http/json in otlptracehttp
MrAlias
left a comment
There was a problem hiding this comment.
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>
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
Signed-off-by: Shiqi Yang <syang482@bloomberg.net> Assisted-by: Claude Opus 4.7
MrAlias
left a comment
There was a problem hiding this comment.
The OTLP/JSON correctness issues I raised earlier look addressed in the current revision. I just have one remaining doc nit inline.
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
There was a problem hiding this comment.
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
Encodingtype +WithEncodingpublic option tootlptracehttp, and a generatedProtocolconfig (with env var parsing) shared between the trace HTTP and gRPC exporters. - Add a new
internal/otlpjsonpackage implementing OTLP JSON Protobuf encoding for trace requests (custom structs) and responses (protojson). - Switch
client.goto choose Content-Type, request marshaling, and response decoding based oncfg.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
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
|
Signed-off-by: Shiqi Yang <syang482@bloomberg.net>
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.
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
Resolves #8150
My initial impression to this issue was to just add a new option like
WithEncodingto switch betweenprotobufandjson. But after realizing that users can useOTEL_EXPORTER_OTLP_[TRACES_]*environment variables to control the configuration and the OTLP specification has already definedOTEL_EXPORTER_OTLP_[*_]PROTOCOLto supportgrpc,http/protobufandhttp/json, I decided to add a new option typeProtocolto control the protocol/encoding.Let me know if this is the intended usage of the OTLP protocol.