Repository navigation
feat(audit): otlp-logs sink, on the SDK's pipeline rather than a hand encoder - #35
Merged
Merged
Conversation
… 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]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 counteddelivered/droppedand 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:WithEndpointURLdoes not append/v1/logs. Records were posting to/, where a collector 404s and they're gone.gateway/otel.gohad already hit this for traces and documented it; the same normalization now applies, and my comment claiming the opposite is deleted.service.namearrived asunknown_service. I usedsemconv/v1.26.0, which conflicts on schema URL with the SDK's default resource, soresource.Mergeerrored and my fallback silently shipped unlabelled records. Matched tov1.43.0(what the tracer uses) and re-verified:service.name: Str(fold).Collector output after the fixes:
Details
IsAbs:url.Parse("collector:4318")yields schemecollector, whichIsAbsaccepts 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.mcp.method,fold.upstream,fold.tenant,enduser.id), so a trace and its audit record join on the same keys.WARNnotERROR— 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,otlploghttpare 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.govulncheckclean,make checkgreen.🤖 Generated with Claude Code