Commit 35f65d0
[Tracing] Add experimental http/protobuf support for OTLP traces export (#8645)
## Summary of changes
Adds `http/protobuf` support to the OTLP traces exporter introduced in
#8211, which introduced the exporter and `http/json` support.
This feature is enabled by setting `OTEL_TRACES_EXPORTER=otlp` and
`OTEL_EXPORTER_OTLP_TRACES_PROTOCOL=http/protobuf` (or the parent
`OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf`).
## Reason for change
When #8211 landed, `http/json` was the only functional OTLP traces
protocol — setting any other protocol would fall back (with a log
message) to the Datadog MessagePack encoding.
`http/protobuf` is the OTLP default protocol per the OpenTelemetry
specification and is what most OTel collectors, Datadog Agent included,
expect to receive, so we need to support it to be useful out-of-the-box
for users adopting the OTLP traces export.
## Implementation details
### Serializer
Adds `Datadog.Trace.OpenTelemetry.Traces.OtlpTracesProtobufSerializer`,
a new `ISpanBufferSerializer` that emits the [OTLP
`ExportTraceServiceRequest`](https://github.com/open-telemetry/opentelemetry-proto/blob/v1.2.0/opentelemetry/proto/trace/v1/trace.proto)
protobuf payload directly into `SpanBuffer`'s output buffer:
- The `resource_spans` and `scope_spans` envelopes are opened on the
first `SerializeSpans` call, span entries are appended per chunk, and
`FinishBody` patches the two length-prefix placeholders using absolute
positions into the destination buffer.
- The serializer respects the same per-span / per-event / per-link
attribute count limits (`128`) as `OtlpTracesJsonSerializer`, and
re-uses the `OtlpMapper` logic to map resource attributes and tags onto
the serialized spans.
- `OtlpTracesProtobufSerializer` is **stateful** (it tracks the two
length-placeholder positions), so `AgentWriter` now creates a fresh
instance for the front and back buffers rather than sharing one — the
previous shared `OtlpTracesJsonSerializer` was stateless and didn't need
this.
### Vendored OpenTelemetry SDK
Builds on the protobuf primitives vendored from the OpenTelemetry .NET
SDK in #7653 (`ProtobufSerializer`, `ProtobufWireType`):
- Adds new field-number constant files:
`ProtobufOtlpTraceFieldNumberConstants` and
`ProtobufOtlpResourceFieldNumberConstants` (split out so the OTLP trace
serializer only depends on what it needs).
- Removes the `#if NETCOREAPP3_1_OR_GREATER` guard from the vendored
`ProtobufSerializer` — now that we vendor a `Span<>` polyfill the
serializer compiles and runs on all supported runtimes (.NET Framework
4.6.1+).
- Drops the matching `#if NET6_0_OR_GREATER` guard around the
`SubmitsOtlpTraces` integration test (`http/protobuf` and `http/json`
both run on .NET Framework now too).
### Wiring
- `ExporterSettings`: `OtlpProtocol.HttpProtobuf` now resolves to
`TracesEncoding.OtlpProtobuf` instead of falling back to `DatadogV0_4`.
- `AgentWriter.GetSpanSerializer`: selects
`OtlpTracesProtobufSerializer` when `TracesEncoding == OtlpProtobuf`.
- `ApiOtlp.SendTracesAsync`: chooses `application/x-protobuf` vs
`application/json` for the request `Content-Type` based on
`_tracesEncoding`. Adds the `application/x-protobuf` MIME type constant
to `Datadog.Trace.Agent.Transports.MimeTypes`.
- `supported-configurations.yaml`: documents `http/protobuf` as a valid
value for `OTEL_EXPORTER_OTLP_TRACES_PROTOCOL` and regenerates
`ConfigurationKeys.OpenTelemetry.g.cs` for all TFMs.
## Test coverage
- **Unit tests**: New `OtlpTracesProtobufSerializerTests` exercises the
serializer end-to-end using `Google.Protobuf` and a little custom
parsing. Test cases include:
- Empty buffer (`FinishBody` returns 0)
- Multiple traces reported in a single-chunk
- Serializing span events/links/status
- Exceeding buffer `maxSize` honoring behavior
- Exceeding span limits
- **Integration tests**: `OpenTelemetrySdkTests.SubmitsOtlpTraces` now
runs both `http/json` and `http/protobuf` cases for the Datadog SDK on
all TFMs.
- **Snapshot unification**: To keep one Datadog-SDK snapshot regardless
of OTLP protocol, snapshots for `http/protobuf` are normalized to the
`http/json` shape via scrubbers that translate the test agent's protobuf
rendering (snake_case field names, string-form enum values like
`SPAN_KIND_SERVER`) into the JSON serializer's shape (camelCase field
names, integer enum values).
- **Snapshot rename**: `SubmitsOtlpTraces_DD_http_json.verified.txt`
renamed to `SubmitsOtlpTraces_DD.verified.txt` (one snapshot now covers
both protocols).
## Other details
With this PR, `http/json` and `http/protobuf` are both functional;
`grpc` still falls back to Datadog MessagePack encoding with a startup
warning.
### Follow-up work
- Implement the `grpc` OTLP traces protocol
- Add OTLP traces telemetry counts (the `TODO: Telemetry - Record OTLP
Traces API submissions` in `ApiOtlp.SendTracesAsync` still applies)
- Honor `OTEL_EXPORTER_OTLP_TRACES_TIMEOUT` in `ApiOtlp` (still unused)
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent dc3f873 commit 35f65d0
35 files changed
Lines changed: 7959 additions & 149 deletions
File tree
- tracer
- src/Datadog.Trace
- Agent
- Transports
- Configuration
- Generated
- net461/Datadog.Trace.SourceGenerators/ConfigurationKeysGenerator
- net6.0/Datadog.Trace.SourceGenerators/ConfigurationKeysGenerator
- netcoreapp3.1/Datadog.Trace.SourceGenerators/ConfigurationKeysGenerator
- netstandard2.0/Datadog.Trace.SourceGenerators/ConfigurationKeysGenerator
- OpenTelemetry
- Stubs
- Traces
- Vendors/OpenTelemetry.Exporter.OpenTelemetryProtocol/Implementation/Serializer
- test
- Datadog.Trace.ClrProfiler.IntegrationTests
- Datadog.Trace.Tests
- OpenTelemetry/Traces
- Generated
- proto/opentelemetry/proto
- collector/trace/v1
- common/v1
- resource/v1
- trace/v1
- snapshots
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
94 | 94 | | |
95 | 95 | | |
96 | 96 | | |
97 | | - | |
| 97 | + | |
98 | 98 | | |
99 | 99 | | |
| 100 | + | |
100 | 101 | | |
101 | 102 | | |
102 | 103 | | |
103 | 104 | | |
104 | 105 | | |
105 | | - | |
106 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
107 | 109 | | |
108 | 110 | | |
109 | 111 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
| |||
37 | 35 | | |
38 | 36 | | |
39 | 37 | | |
40 | | - | |
41 | 38 | | |
42 | 39 | | |
43 | 40 | | |
| |||
53 | 50 | | |
54 | 51 | | |
55 | 52 | | |
56 | | - | |
57 | | - | |
58 | 53 | | |
59 | 54 | | |
60 | 55 | | |
| |||
196 | 191 | | |
197 | 192 | | |
198 | 193 | | |
199 | | - | |
200 | | - | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
201 | 201 | | |
202 | 202 | | |
203 | 203 | | |
| |||
304 | 304 | | |
305 | 305 | | |
306 | 306 | | |
307 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
8 | 6 | | |
9 | 7 | | |
10 | 8 | | |
| |||
50 | 48 | | |
51 | 49 | | |
52 | 50 | | |
53 | | - | |
54 | | - | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| 12 | + | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
115 | | - | |
116 | | - | |
| 115 | + | |
117 | 116 | | |
118 | 117 | | |
119 | 118 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2676 | 2676 | | |
2677 | 2677 | | |
2678 | 2678 | | |
2679 | | - | |
| 2679 | + | |
2680 | 2680 | | |
2681 | 2681 | | |
2682 | 2682 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
Lines changed: 1 addition & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
136 | 136 | | |
137 | 137 | | |
138 | 138 | | |
139 | | - | |
| 139 | + | |
140 | 140 | | |
141 | 141 | | |
142 | 142 | | |
| |||
0 commit comments