Skip to content

feat(audit): otlp-logs sink, on the SDK's pipeline rather than a hand encoder - #35

Merged
blakebauman merged 1 commit into
mainfrom
feat/otlp-logs-sink
Aug 11, 2026
Merged

blakebauman merged 1 commit into
mainfrom
feat/otlp-logs-sink

Conversation

@blakebauman

Copy link
Copy Markdown
Member

Completes roadmap Horizon 1 item 4 (after #34). Audit events now emit as OpenTelemetry log records over OTLP/HTTP, so the trail lands wherever a deployment's telemetry already goes.

A reversal worth stating

I started this planning to encode OTLP JSON by hand, to avoid a v0.x dependency. Reading the spec changed that: proto3 JSON renders 64-bit fields as strings, severity is a numeric enum with a specified text mapping, and attribute values are tagged unions. None of that is fold's problem to solve twice, and the collector run below shows I'd have gotten it wrong.

So the sink is LoggerProvider → batch processor → otlploghttp, and fold supplies only what's genuinely its own: the event→record mapping and the accounting. The exporter is wrapped so every export is counted delivered/dropped and abandoned batches are dead-lettered in their converted form (labelled, so a replay tool knows the shape). Without that, this would be the one destination whose failures no metric reports — undoing what #34 just established.

Two bugs a stand-in server could never have caught

Found by emitting into a real otel/opentelemetry-collector:

  1. WithEndpointURL does not append /v1/logs. Records were posting to /, where a collector 404s and they're gone. gateway/otel.go had already hit this for traces and documented it; the same normalization now applies, and my comment claiming the opposite is deleted.
  2. service.name arrived as unknown_service. I used semconv/v1.26.0, which conflicts on schema URL with the SDK's default resource, so resource.Merge errored and my fallback silently shipped unlabelled records. Matched to v1.43.0 (what the tracer uses) and re-verified: service.name: Str(fold).

Collector output after the fixes:

SeverityText: WARN     SeverityNumber: Warn(13)
Body: Str(tools/call billing__invoice → denied)
  -> mcp.method: Str(tools/call)      -> fold.tenant: Str(acme)
  -> fold.outcome: Str(denied)        -> enduser.id: Str(alice)
  -> fold.latency_ms: Int(42)
Resource: service.name: Str(fold)

Details

  • Validation checks the scheme, not IsAbs: url.Parse("collector:4318") yields scheme collector, which IsAbs accepts and the exporter then replaces with its own default endpoint — sending an audit trail somewhere nobody asked for. A test refuses all three bad shapes.
  • Attributes mirror fold's span names (mcp.method, fold.upstream, fold.tenant, enduser.id), so a trace and its audit record join on the same keys.
  • Severity follows outcome, refusals at WARN not ERROR — policy denying a call is the gateway working, and logging it as an error trains people to ignore errors.

Dependency cost, stated

otel/log, sdk/log, otlploghttp are v0.21.0 — pre-1.0, in a project whose own contract is frozen. Blast radius is one file behind a sink nobody must enable. govulncheck clean, make check green.

🤖 Generated with Claude Code

… encoder

Completes roadmap Horizon 1 item 4. Audit events now emit as OpenTelemetry log
records over OTLP/HTTP, so the trail lands wherever the rest of a deployment's
telemetry already goes.

This reverses the approach I started with. The first plan was to encode OTLP
JSON directly and avoid a v0.x dependency, which sounds prudent until you read
the spec and notice where a hand-rolled emitter goes wrong: proto3 JSON renders
64-bit fields as strings, severity is a numeric enum with a specified text
mapping, and attribute values are tagged unions. None of that is fold's problem
to solve twice. The sink is built on LoggerProvider → batch processor →
otlploghttp instead, and fold supplies only what is genuinely its own.

What is its own is the accounting. The exporter is wrapped so every export is
counted delivered or dropped and abandoned batches are dead-lettered in their
converted form, labelled so a replay tool knows which shape it is reading.
Without that this would have been the one destination whose failures no metric
reports, which would undo the guarantee the other sinks just gained.

Two bugs a stand-in HTTP server could never have caught, both found by emitting
into a real collector:

  - WithEndpointURL does not append /v1/logs. Records were posting to "/",
    where a collector 404s and they are simply gone. gateway/otel.go had
    already hit this for traces and documented it; the same normalization now
    applies here, and the comment claiming the opposite is gone.
  - service.name arrived as "unknown_service". semconv v1.26.0 conflicts on
    schema URL with the resource the SDK builds by default, so resource.Merge
    errored and the fallback shipped unlabelled records. Matched to v1.43.0,
    the version the tracer already uses, and re-verified against the collector.

Config validation checks the URL's scheme rather than IsAbs: url.Parse reads
"collector:4318" as scheme "collector", which IsAbs accepts and the exporter
then quietly replaces with its own default endpoint — sending an audit trail
somewhere nobody asked for. A test asserts all three bad shapes are refused.

Event fields map to attributes under the same names fold's spans use, so a
trace and its audit record join on the same keys. Severity follows the outcome,
with refusals at WARN rather than ERROR: policy denying a call is the gateway
working, and logging it as an error trains an operator to ignore errors.

The dependency cost is stated rather than hidden: otel/log, sdk/log, and
otlploghttp are v0.21.0, pre-1.0 in a project whose own contract is frozen.
The blast radius is one file behind a sink nobody has to enable, which is the
trade taken knowingly. govulncheck clean.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@blakebauman
blakebauman merged commit 259c65e into main Aug 11, 2026
6 checks passed
@blakebauman
blakebauman deleted the feat/otlp-logs-sink branch August 11, 2026 13:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant