Skip to main content

Module agentless_encoder

Module agentless_encoder 

Source
Expand description

Agentless APM JSON encoder.

Encodes Datadog v04 trace chunks to the JSON body accepted by the Datadog HTTP trace intake (POST /v1/input).

§Differences from the regular agent (msgpack v04) encoding

  • Wire format: JSON, wrapped as {"traces": [ {hostname, env, ..., spans: [...] }, ... ]}. Per-trace metadata (hostname, env, language*, tracerVersion, runtimeID, containerID) is inlined on each trace instead of being carried in request headers. Hostname is always emitted
  • IDs: trace_id, span_id, parent_id are lowercase hex strings (16 chars; 32 for span-link trace IDs)
  • 128-bit trace IDs: only the low 64 bits go into trace_id; the _dd.p.tid meta tag carries upper 64 bits
  • Span links / events: not top-level fields. They are JSON-stringified into meta["_dd.span_links"] and meta["events"], each truncated to 25_000 chars. No top-level links field is emitted. If meta attributes for “_dd.span_links” of “events” are already attached to the span we will keep existing fields and the span level field will be dropped
  • Stats / top-level flags: the intake has no trace-agent to compute them, so the encoder injects meta["_dd.compute_stats"]="1" on the first span of each chunk and metrics["_trace_root"]=1 where applicable.
  • Non-finite metrics (NaN/Inf) are dropped (JSON can’t represent them).

TODO: span normalization (service/name/resource/type truncation + defaults)

Functions§

encode_payload
Encode the given traces to the agentless JSON payload (/v1/input body).
encode_payload_from_v1
V1-native analog of encode_payload. Downgrades v1’s unified attribute model back to the same meta/metrics/meta_struct-shaped wire fields, so the emitted JSON body is equivalent to what a v0.4 tracer would produce for the same trace — see [crate::msgpack_encoder::v04::span_v1] for the mapping table this mirrors. Chunk-level context (trace_id, origin, priority, sampling_mechanism, dropped_trace, chunk attributes) is propagated into every span, matching the v1::TraceChunk-level granularity v1 operates at.