weaver icon indicating copy to clipboard operation
weaver copied to clipboard

live-check: make SampleLog body a structured value (AnyValue)

Open lmolkova opened this issue 1 month ago • 1 comments

Follow-up to #1873.

SampleLog.body is Option<String> (crates/weaver_live_check/src/sample_log.rs), but in OTel the log body is an AnyValue. #1873 stops rendering OTLP bodies in Rust debug format: string bodies are kept as-is, and maps, arrays, bytes and numbers are serialized to a compact JSON string. That keeps the field type, but policies and matchers still can't inspect structured bodies without parsing a string.

Proposal: make SampleLog.body a JSON value (Option<serde_json::Value>), converted the same way as attribute values (kvlist → object, bytes → base64 string, array elements preserved).

Impact to handle:

  • CEL matchers: body becomes a dynamic value; string functions such as body.contains(...) only work on string bodies. Update docs (docs/matchers.md) and tests.
  • Rego policies: input.sample.log.body may be an object or array; contains(...) on it would need a type check.
  • JSON sample input format and schema: body accepts any JSON value (string inputs keep working).
  • Reports and --emit-otlp-logs output: the body shows as structured JSON.
  • weaver_live_check public API: changing the field type is a breaking change, so the changelog should mark it as one.

lmolkova avatar Oct 31 '26 17:10 lmolkova

@lmolkova One comment on bytes → base64 string - after #1873, a bytes_value reaches a policy as a base64 JSON string (conversion.rs L87), the same as a base64 string_value. The GenAI conventions say "a property with "format": "binary" SHOULD be recorded as a byte array, not a string" (gen-ai-spans.md L529-L533), so live-check can't catch an instrumentation that records base64 text there. open-telemetry/semantic-conventions-genai#767 moves the OpenAI blob content from base64 strings to bytes, and the check can't tell the two apart. I think it would help if the conversion kept the original type somewhere a policy can read it, for bodies and attributes alike. I'm happy to help with a test case if needed.

girishkvs avatar Dec 03 '26 03:12 girishkvs