Module attrs

Module attrs 

Source
Expand description

Helpers for OTel attribute / AnyValue → JSONB translation Converts OTel KeyValue arrays + scalar AnyValue instances to JSONB bytes.

Mapping follows the plan’s “Attribute value encoding” table:

  • string → JSON string
  • int / double / bool → JSON number / bool
  • bytes → base64-encoded string (existing properties consumers expect text)
  • array / kvlist → recursive JSON

The output is a JSONB-encoded {key → value} blob suitable for the properties columns across log_entries, measures, and otel_spans.

Functions§

any_value_to_jsonb
Converts an AnyValue to a jsonb::Value. Recursively handles arrays and kvlists.
any_value_to_string
Renders AnyValue to a flat string for fields that need a textual form (e.g., the msg column when an OTel log body is structured).
attrs_to_jsonb
Serializes a flat (key → value) map (with optional extra entries layered on top) to JSONB bytes. Output ordering is alphabetical, matching serialize_properties_to_jsonb.
scope_extras
Builds the per-row otel.scope.* properties (name, version, attr.*, schema_url) that ride alongside row attributes in the JSONB properties column. Skips empty fields so absent scopes don’t pollute the output.
severity_number_to_level
Maps OTel severity_number (1–24) to micromegas Level (1–6).
to_jsonb_bytes
Encodes a JsonbValue to its on-wire JSONB bytes.