Skip to main content

Module json

Module json 

Source
Expand description

OTLP/HTTP with a JSON body.

JSON is a normative encoding of OTLP, not an extra: the browser SDK emits it, and it is what anyone reaches for with curl. The three endpoints in crate::receiver dispatch on content-type and land here.

No new dependency. The document is parsed by the same yaml_rust2 loader that reads queries and config (api::parse), because YAML 1.2 is a superset of JSON β€” so this file is only the mapping from a parsed document onto the prost structs. It also means a KYAML body works, which is principle 5 falling out for free rather than being built.

Two places the OTLP JSON mapping is not the canonical protobuf one, and both are why an off-the-shelf reflective decoder is wrong here:

  • trace_id, span_id and parent_span_id are hex, not base64. A 32-character hex string is also valid base64, so a canonical decoder does not fail on one β€” it silently produces 24 bytes of nonsense. Every other bytes field really is base64.
  • 64-bit integers are strings. time_unix_nano arrives as "1544712660300000000" because a JSON number cannot hold it exactly. Numbers are accepted too; emitters disagree.

Everything here is lenient in the directions the spec allows and strict where being lenient would store the wrong bytes: a field name may be either lowerCamelCase or the original proto name, an enum may be its name or its number, but an id of the wrong length is an error rather than a truncation.

ConstantsΒ§

SEVERITY πŸ”’
SPAN_KIND πŸ”’
STATUS_CODE πŸ”’
TEMPORALITY πŸ”’

FunctionsΒ§

any_value πŸ”’
base64 πŸ”’
Standard base64 with padding, which is what proto3 JSON uses for every bytes field that is not an id. URL-safe input is accepted because it costs two match arms and a rejected attribute value is a lost attribute value.
boolean πŸ”’
buckets πŸ”’
data_points πŸ”’
dropped πŸ”’
enumerate πŸ”’
An enum, as its proto name or as its number. names[i] is the name of value i; every OTLP enum reached from here numbers from zero with no gaps.
exemplars πŸ”’
exp_histogram_points πŸ”’
f πŸ”’
Look up one field.
float πŸ”’
A double. proto3 JSON spells the three special values as strings, and lets any number arrive as a string as well.
floats πŸ”’
hex πŸ”’
A trace or span id: lowercase or uppercase hex, exactly want bytes.
histogram_points πŸ”’
i32f πŸ”’
int πŸ”’
A 64-bit integer, as a JSON number or β€” the proto3 JSON default, because a double cannot hold one exactly β€” as a string.
key_values πŸ”’
list πŸ”’
Absent, null and β€œpresent but empty” are the same thing to every caller here: proto3 has no way to tell them apart on the wire either.
log_record πŸ”’
logs
metric_of πŸ”’
metrics
missing πŸ”’
number_points πŸ”’
number_value πŸ”’
The asDouble / asInt oneof, shared by NumberDataPoint and Exemplar.
opt_float πŸ”’
optional double in the proto, so absent and 0 are different values and the difference is visible in a histogram.
resource πŸ”’
s πŸ”’
scope πŸ”’
scope_logs πŸ”’
scope_metrics πŸ”’
scope_spans πŸ”’
span πŸ”’
summary_points πŸ”’
temporality πŸ”’
top πŸ”’
The one top-level member of an export request, in either dialect.
traces
u32f πŸ”’
uint πŸ”’
Unsigned 64-bit. Values above i64::MAX are legal for fixed64/uint64 and arrive as strings, so they are parsed as u64 rather than routed through int, which would reject them.
uints πŸ”’

Type AliasesΒ§

R πŸ”’