Repository navigation
feat(telemetry): count dropped OTLP log records and test against a real collector - #304
Merged
Merged
Conversation
The SDK BatchProcessor never blocks on emit: with a full queue it overwrites the oldest record and reports the drop only to its internal logger, without the scope. Wrap it so records awaiting export never exceed the queue size and drop the newest record instead, counted in openartifact_telemetry_log_records_dropped_total by instrumentation scope. The counter is created before the log provider and registered with the metrics registry, which is built later.
…ners otelcoltest starts otel/opentelemetry-collector-contrib (same digest as docker-compose.yml) with OTLP gRPC and HTTP receivers and a file exporter, and exposes the exported OTLP JSON lines. The first test exports a log record through the provider telemetry.Setup installs, over both protocols, and reads it back.
gjed
force-pushed
the
feat/otlp-log-plumbing
branch
from
October 28, 2026 08:38
c2d92ef to
0debb0e
Compare
Coverage
Go by area
Web by area (lines)
|
M0Rf30
approved these changes
Oct 28, 2026
M0Rf30
left a comment
Collaborator
There was a problem hiding this comment.
Reviewed against otel sdk/log v1.47.0 internals: the in-flight accounting keeps the inner queue from overflowing (conservative: a dequeued batch counts until its export starts), OnEmit stays non-blocking, scope label cardinality is fixed by code. Unit test is deterministic; the collector test ran in the integration job.
Non-blocking follow-ups:
- ForceFlush with an expiring context leaks the slots of skipped chunks, shrinking the limit permanently. Nothing calls it today, but #192/#193 consumers might: worth fixing (or guarding with a test) before then.
- otelcoltest.Image is pinned by hand to the compose digest that Dependabot bumps; a test asserting both digests match would catch drift.
- Drop-newest instead of drop-oldest is the right trade-off for per-scope counting; thanks for documenting it.
This was referenced Oct 28, 2026
Merged
This was referenced Oct 28, 2026
gjed
added a commit
that referenced
this pull request
Oct 28, 2026
With telemetry.otlp.audit on, every audit event is also emitted on the openartifact.audit logger of the global provider as a log event named openartifact.audit, the action an attribute. Attributes follow the export fields and details_json keys under openartifact.audit.*, and the record carries the entry id, time and the caller's span context, so the stream and `oa audit export` dedupe on id. The event is emitted after the insert whatever its result. auth.login_failed leaves the typed username out of the stream. Drops are counted by the #304 processor under scope openartifact.audit; nothing waits for the collector. The monitoring docs give the attribute schema as a contract, the delivery semantics, the http.request volume and a Collector routing example to Splunk HEC and Loki. Closes #193
gjed
added a commit
that referenced
this pull request
Oct 28, 2026
With telemetry.otlp.audit on, every audit event is also emitted on the openartifact.audit logger of the global provider as a log event named openartifact.audit, the action an attribute. Attributes follow the export fields and details_json keys under openartifact.audit.*, and the record carries the entry id, time and the caller's span context, so the stream and `oa audit export` dedupe on id. The event is emitted after the insert whatever its result. auth.login_failed leaves the typed username out of the stream. Drops are counted by the #304 processor under scope openartifact.audit; nothing waits for the collector. The monitoring docs give the attribute schema as a contract, the delivery semantics, the http.request volume and a Collector routing example to Splunk HEC and Loki. Closes #193
M0Rf30
added a commit
that referenced
this pull request
Oct 29, 2026
* feat(audit): record outcome, user, token, request id and HTTP status Every audit entry now carries outcome (success/failure), the authenticated username, the API token id, the X-Request-ID and the HTTP status in details_json, so `oa audit export` and the coming OTLP stream (#193) describe an entry with the same fields. AuditMiddleware attaches the request to the context (audit.WithRequest), so the events handlers record pick these up without each emitter filling them in. The RBAC principal now keeps the id of the token it authenticated. * feat(audit): assign the entry id and time when the event is recorded Log() now generates the entry UUID and the event time (truncated to the microsecond Postgres keeps) and InsertAuditLog writes them, falling back to the column defaults when unset. The row no longer gets its id and created_at after an unbounded wait in the queue, so anything emitted alongside it can carry the same identity. * feat(audit): stream audit events as OTLP log events With telemetry.otlp.audit on, every audit event is also emitted on the openartifact.audit logger of the global provider as a log event named openartifact.audit, the action an attribute. Attributes follow the export fields and details_json keys under openartifact.audit.*, and the record carries the entry id, time and the caller's span context, so the stream and `oa audit export` dedupe on id. The event is emitted after the insert whatever its result. auth.login_failed leaves the typed username out of the stream. Drops are counted by the #304 processor under scope openartifact.audit; nothing waits for the collector. The monitoring docs give the attribute schema as a contract, the delivery semantics, the http.request volume and a Collector routing example to Splunk HEC and Loki. Closes #193 * docs(monitoring): list PATCH among the audited writes The recorded-writes list disagreed with the Volume section and the middleware, which audits PATCH too. * test(middleware): fail instead of hanging when an audit event is missing Every event is inserted once Shutdown returns, so check the count before receiving: a missing event used to block until the go test timeout. * fix(audit): stream the event from Log, before the database queue The writer inserted first and streamed second, so a hung database (up to 10 s per insert) filled the queue and Log dropped events that were then neither stored nor streamed. Log now emits right after capture; Emit never waits for the collector. * docs(monitoring): tell audit pollers to overlap windows and dedupe on id created_at is stamped before the queue, so rows can commit out of timestamp order by the queue delay and by clock skew between replicas. * feat(audit): send client address and HTTP method, route and status under semconv names Collector processors and backends key on client.address, http.request.method, http.route and http.response.status_code. The contract is add-only, so they go out next to the openartifact.audit.* names now; body and details_json are unchanged. * docs(monitoring): state that audit stream attributes are personal data Client addresses and actor identifiers reach every backend the Collector forwards to, with that backend's retention. * docs(upgrading): note the audit stream and the new meaning of created_at Installs that already set OPENARTIFACT_OTLP_AUDIT start streaming on upgrade, and created_at is now the time the event is recorded, so pollers should overlap their windows. * chore: sort package formats alphabetically (#329) * feat(composer): hosted Composer repositories (#328) (#330) * feat(composer): hosted Composer repositories (#328) * fix(composer): http-basic host key includes the port * fix(composer): fuzz targets in the package's own test file * fix(composer): keep the fuzz targets as the only in-package test file * fix(composer): fuzz seeds build under the OSS-Fuzz testing shim * feat(composer): proxy and group repositories (#328) (#331) * feat: experimental frontend telemetry behind a same-origin relay (#222) (#320) * feat(telemetry): telemetry.frontend.enabled and telemetry.frontend.endpoint Configuration of the experimental frontend telemetry (#222): one toggle, off by default, that needs telemetry.otlp.enabled, and the OTLP/HTTP URL the relay forwards to. Without an endpoint of its own the relay uses telemetry.otlp.endpoint, which then has to speak OTLP/HTTP; with the grpc protocol the endpoint is required and Validate says so. Env overrides OPENARTIFACT_TELEMETRY_FRONTEND_ENABLED and OPENARTIFACT_TELEMETRY_FRONTEND_ENDPOINT, documented in .env.example, openartifact.example.yaml and docker/.env.example; compose passes both through, the endpoint defaulting to the otel-collector profile's 4318. The server warns when the toggle is on without OTLP. * feat(api): frontend telemetry relay, settings endpoint and counter POST /api/v1/telemetry/{traces,logs} forwards the web UI's OTLP/HTTP export requests unchanged to the Collector (telemetry.frontend.endpoint, or the shared OTLP/HTTP endpoint) with the shared headers, so the Collector stays internal and the CSP stays same-origin. Browser sessions only, with the CSRF header: anonymous 401, API tokens 403. The body must be uncompressed application/x-protobuf (415), at most 1 MiB through MaxBodyMiddleware (413). Feature off and any other signal answer 404; an unreachable or failing Collector 502 after at most 10 seconds, a payload it rejects 400. Redaction stays in the Collector. GET /api/v1/telemetry/frontend returns enabled and sample_ratio (telemetry.otlp.sampleRatio) to signed-in users, 404 while off. RBAC lets sessions reach both routes as self-service; the relay is not audited (it changes nothing and fires every few seconds per open UI). openartifact_frontend_telemetry_requests_total{signal,result} counts relayed, rejected and failed requests. * feat(web): client span and traceparent per API call send() starts a client span for every API call once a span factory is installed, sends its W3C traceparent so the server span becomes its child (telemetry.HTTPMiddleware already continues it), and ends it with the response status or as failed when no response arrives. Without a factory, which is the default, calls are unchanged. This replaces the deprecated fetch/XHR instrumentations; the frontend telemetry wrapper installs the factory. * feat(web): load the OpenTelemetry wrapper on demand Once a user is signed in, the UI asks GET /api/v1/telemetry/frontend and only on a 200 imports web/src/telemetry/otel.ts, a chunk of its own that the service worker does not precache. While the feature is off the default bundle has no OpenTelemetry code and nothing else is requested. The wrapper is experimental and pinned to exact versions: @opentelemetry/api 1.10.0, sdk-trace 3.0.0, sdk-logs 3.0.0, resources 3.0.0, exporter-trace-otlp-proto and exporter-logs-otlp-proto 0.300.0, browser-instrumentation 0.9.0. It records unhandled errors (browser-instrumentation errors, which supersedes instrumentation-web-exception), errors caught by Vue's error handler, and Core Web Vitals as log events, plus the API client spans sampled with the server's sample_ratio. No console, user-action, document-load or navigation instrumentation. Resource service.name=openartifact-web and the web build's service.version. Nothing is registered globally or stored in cookies or local storage. Exports go to the same-origin relay with the CSRF header, in batches of at most 64 records. * test(web): telemetry routes bypass the service worker The /api prefix already keeps GET /api/v1/telemetry/frontend and the POST relay away from the worker; pin it so the telemetry routes stay network-only if the bypass list changes. * test(apifuzz): do not fuzz the frontend telemetry relay POST /api/v1/telemetry/{signal} takes application/x-protobuf, for which Schemathesis has no serializer, so api-fuzz failed with "Serialization not possible" in every pass. The relay also forwards each request to the collector, like the other operations already excluded for calling out to the network. Its status matrix is covered by the Go tests. * fix(api): refuse redirects from the telemetry collector The relay client followed redirects, so a 307 or 308 from the collector replayed the body and the otlp.headers (collector credentials) to the Location. Go strips only Authorization, Cookie and WWW-Authenticate on a cross-host redirect, not a custom key header. A 3xx now answers 502, as in internal/webhook and internal/federation. Also note on the client that it is deliberately not the SSRF-safe one: the collector is operator configuration and usually internal. * fix(telemetry): do not trace the frontend telemetry relay Every open UI posts an export every few seconds and the browser sends no traceparent, so each export became a new root trace with its DB spans, sent to the same collector. Skip POST /api/v1/telemetry/{traces,logs} like the probes. * fix(web): stop telemetry on sign-out Nothing stopped telemetry when the user signed out or the session expired: the client span factory stayed installed and the batch exporters kept posting to the relay, each export failing with 401. stopTelemetry() clears the span factory and the error recorder and shuts down both providers and both instrumentations; it is called when the signed-in state turns false. A sign-in that is stopped while the settings or the chunk are still loading no longer starts, and the next sign-in starts telemetry again. * docs(telemetry): the relay accepts records from every signed-in account service.name is set by the sender and the relay needs no role, so a user can post records under any resource attributes, the server's own service.name included. Say so, and tell operators to treat the data as untrusted. * fix(docker): redact traces and logs in the bundled collector config Frontend telemetry defaults to the compose collector, which had no redaction processor, so enabling the toggle exported raw exception messages and stack traces. Add the redaction/frontend processor that the docs describe to the traces and logs pipelines of docker/otel-collector.yaml. It masks url.* attributes and query strings, and applies to the server's own traces and logs too. * fix(api): cap the concurrent forwards of the telemetry relay Each forward holds up to 1 MiB of request body in memory for up to 10 seconds, and the rate limit is per client, so a hung collector had no global bound. At most 32 forwards run at once; the next request answers 503 with Retry-After, which the browser exporter retries, and counts as rejected. * chore(web): regenerate bun.lock with Bun 1.4.4 The lockfile of the OpenTelemetry dependencies was written by an older Bun than the 1.4.4 that CI pins, which dropped the libc selectors of the rolldown and jscpd Linux bindings. Regenerate it from the base lockfile with Bun 1.4.4 so the diff holds only the @opentelemetry entries. * refactor(telemetry): rename isProbe to untraced It also covers the frontend telemetry relay's exports, which are not probes. Name it for what it decides and document it. --------- Co-authored-by: M0Rf30 <[email protected]> Co-authored-by: Gianluca Boiano <[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.
What
Shared plumbing for #192 (application logs over OTLP) and #193 (audit events over OTLP), both of which write to the log provider #224 added. No consumer yet.
BatchProcessornever blocks on emit: when its queue is full it overwrites the oldest record and reports the drop only to its internal logger, without the scope.internal/telemetrynow wraps it so the records awaiting export never exceed the queue size (OTEL_BLRP_MAX_QUEUE_SIZE, default 2048); past that it drops the newest record and counts it inopenartifact_telemetry_log_records_dropped_total{scope}. Emitting stays non-blocking.Setuptakes the counter; the server creates it before the provider and registers it with the metrics registry ininitCore(the registry stays where it was:serveruns several times per test process).tests/integration/otelcolteststartsotel/opentelemetry-collector-contrib(same digest asdocker/docker-compose.yml) with OTLP gRPC and HTTP receivers and a file exporter, and exposes the exported OTLP JSON lines (Lines,WaitForLine). Without a container runtime it skips, or fails underCI.TestOTLPLogRecordReachesCollectorexports anopenartifact.auditrecord through the providerSetupinstalls, over both protocols, and reads it back.Notes
SIMPLIFIED:aForceFlushwhose deadline expires mid-export leaks the slots of the chunks it skips. Nothing callsForceFlushon the log provider today.otelcoltest.Imagehas to follow by hand (commented).Checks
make test, the CI integration package set against Postgres 18 (podman),make deadcode,make docs-gen/make docs-checkpass.make linthas one finding inpkg/rpm/dependencies.go:72andreuse lintone incmd/docgen/main.go, both already on main and outside this diff.