Repository navigation
fix(logs): keep the agent's pattern.hash, read Datadog span ids as decimal, throttle the freopen scan - #390
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces rate limiting for scanning log files per process, updates the log pattern extraction limit flag description, and adds support for parsing Datadog's decimal span IDs in OpenTelemetry log attributes. It also ensures that a span ID without a trace ID is kept as a regular attribute. The review feedback suggests extending this logic by adding a parseTraceId helper to correctly parse Datadog's decimal trace IDs as well, along with corresponding test updates to verify both decimal trace and span ID parsing.
…e trace id Datadog's log injection writes 64-bit trace ids in decimal. They were not parsed, so with this branch's decimal span ids a record still got no trace context: a span id without a trace id stays an attribute (#390 review).
…cimal, throttle the freopen scan From the #380 review: - A JSON field named pattern.hash no longer duplicates or replaces the agent's attribute. - dd.span_id is decimal (Datadog's log injection); a 16-digit value was read as hex. A span id without a trace id stays an attribute. - The freopen fallback reads a process's fds at most every 10s: a process that opens its /var/log file for every write triggered it on every write. - A tail reader waiting for its file to appear logs that once. - The pattern extraction limit is per log source, not per container: say so.
…e trace id Datadog's log injection writes 64-bit trace ids in decimal. They were not parsed, so with this branch's decimal span ids a record still got no trace context: a span id without a trace id stays an attribute (#390 review).
0e3fdf5 to
3cce511
Compare
|
Thanks, this covers the #380 review. The Three small things for a later pass, none blocking:
|
Summary
Follow-up to #380 (from its review).
pattern.hash: a JSON log field with this name was exported next to the agent's own attribute, so a record had twopattern.hashkeys and a backend keeping the last one lost the agent's. The agent's value is now the only one.dd.span_id, anddd.trace_idfor 64-bit ids, in decimal. A 16-digit span id was read as hex, giving a wrong span id, and a decimal trace id wasn't read at all. Both are now read as decimal; a decimal trace id becomes the lower half of the OpenTelemetry trace id (Datadog's mapping), and a 32-character hexdd.trace_id(128-bit) is read as before.--enable-dynamic-log-tailing, off by default): a process that opens its/var/logfile for every write (PHP'serror_log, a shell's>>) made the agent read all of its fds on every write, on the registry's event loop. The scan now runs at most every 10s per process.--log-pattern-extraction-limitapplies per log source (a file or a container's output), not per container.Engineering detail
Tests:
TestLogRecordAttrscovers thepattern.hashcollision, hex trace context, a 16-digit decimaldd.span_idwith a 128-bit hexdd.trace_id, a decimal 64-bitdd.trace_id, and a span id without a trace id.CI: gofmt, goimports, vet, golangci-lint,
go test(excluding/containers) and the build pass in a Linux container with Go 1.26.5.Local e2e: I built agent binaries from this branch and from main and ran each as a systemd service on a local Debian 12 VM (kernel 6.1), with dynamic log tailing on, exporting logs to its own OpenTelemetry collector. A unit wrote JSON log lines to the journal.
pattern.hash: on main, a record carrying"pattern.hash":"spoofed"had twopattern.hashattributes, one of themspoofed. On this branch it had one, the agent's.dd.span_id"1234567890123456": main exported span id1234567890123456(the digits read as hex); this branch exported000462d53c8abac0, the decimal value.dd.trace_id"1234567890123456" withdd.span_id"987654321": main exported no trace context and kept both as attributes; this branch exported trace id0000000000000000000462d53c8abac0and span id000000003ade68b1.span_idwith no trace id: main set it as the record's span id; this branch kept it as aspan_idattribute and left the span id empty./var/logfile, opening it for every write, for 30s. Agent CPU per write: main 37µs (33.2s for 897,666 writes), this branch 28µs (29.0s for 1,029,894 writes). The rest of that cost is handling each open event, which this change doesn't touch. With a process holding only a few fds the difference was within noise. The file was tailed by both.