Back to all reviewers

Format observability test data

cloudflare/workerd
Based on 2 comments
JavaScript

When writing tests for observability systems (tracing, metrics, logging), structure test assertions to be easily readable and debuggable. Instead of placing complex JSON outputs or structured data on single lines, split them across multiple lines with proper formatting.

Observability JavaScript

Reviewer Prompt

When writing tests for observability systems (tracing, metrics, logging), structure test assertions to be easily readable and debuggable. Instead of placing complex JSON outputs or structured data on single lines, split them across multiple lines with proper formatting.

This approach significantly improves the debugging experience when tests fail, as diff outputs clearly show which specific parts of the observability data don’t match expectations. For example, instead of:

let expected = [
  '{"type":"onset","executionModel":"stateless","scriptTags":[],"info":{"type":"custom"}}{"type":"spanOpen","name":"fetch","parentSpanId":"0"}{"type":"spanClose","outcome":"ok"}{"type":"outcome","outcome":"ok","cpuTime":0,"wallTime":0}'
];

Format it as:

let expected = [
  `{"type":"onset","executionModel":"stateless","scriptTags":[],"info":{"type":"custom"}}
   {"type":"spanOpen","name":"fetch","parentSpanId":"0"}
   {"type":"attributes","info":[{"name":"http.request.method","value":"POST"}]}
   {"type":"spanClose","outcome":"ok"}
   {"type":"outcome","outcome":"ok","cpuTime":0,"wallTime":0}`
];

This formatting makes future instrumentation changes much easier to inspect and produces clear, line-by-line diff outputs when assertions fail, allowing developers to quickly identify exactly which observability events or attributes are incorrect.

2
Comments Analyzed
JavaScript
Primary Language
Observability
Category

Source Discussions