Skip to content

feat: experimental frontend telemetry behind a same-origin relay (#222) - #320

Merged
M0Rf30 merged 14 commits into
mainfrom
feat/frontend-telemetry
Oct 29, 2026
Merged

M0Rf30 merged 14 commits into
mainfrom
feat/frontend-telemetry

Conversation

@gjed

@gjed gjed commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Closes #222. Design: #196, question 3.

Experimental browser telemetry behind one toggle, off by default. It covers errors, web vitals and one client span per API call, sent through a same-origin relay to the Collector.

Server

  • telemetry.frontend.enabled (OPENARTIFACT_TELEMETRY_FRONTEND_ENABLED) needs telemetry.otlp.enabled; without it the server logs a warning and the feature stays off. telemetry.frontend.endpoint (OPENARTIFACT_TELEMETRY_FRONTEND_ENDPOINT) is the OTLP/HTTP base URL. It is required with protocol: grpc; otherwise the shared OTLP/HTTP endpoint is used. Both keys are in .env.example, openartifact.example.yaml and docker/.env.example, and compose passes them through.
  • POST /api/v1/telemetry/{traces,logs} forwards the body unchanged with the shared headers. Status codes:
    • session with CSRF header only: anonymous 401, API tokens 403
    • uncompressed application/x-protobuf only (415), at most 1 MiB through MaxBodyMiddleware (413)
    • 404 while off and for any other signal
    • 502 when the Collector is down or failing (10 s timeout), 400 when it rejects the payload
  • The relay is not audited. Every export would otherwise write an audit row.
  • GET /api/v1/telemetry/frontend returns {enabled, sample_ratio}, or 404 while off. The field is snake_case per AGENTS.md, not the issue's sampleRatio.
  • openartifact_frontend_telemetry_requests_total{signal,result} counts relayed, rejected and failed. The 401 and the CSRF 403 are refused before the handler and are not counted.

Web

  • web/src/api/client.ts starts a client span per call and sends its traceparent, so the server span becomes its child. The deprecated fetch/XHR instrumentations are not used.
  • After sign-in, web/src/telemetry/index.ts asks the settings endpoint. Only on a 200 does it dynamically import otel.ts, a separate otel-* chunk. vite.pwa.ts keeps that chunk out of the service worker precache, which would otherwise fetch it with the toggle off.
  • Exact pins: @opentelemetry/api 1.10.0, sdk-trace 3.0.0, sdk-logs 3.0.0, resources 3.0.0, exporter-{trace,logs}-otlp-proto 0.300.0, browser-instrumentation 0.9.0 (errors and web-vitals only). The pins are asserted against bun.lock in a test.
    • instrumentation-web-exception is not used: the opentelemetry-browser migration guide replaces it with browser-instrumentation/experimental/errors, and it only logs through a global logger provider.
    • No console, user-action, document-load or navigation instrumentation. Nothing is registered globally or kept in cookies or local storage.
  • Errors caught by Vue's error handler are recorded too: Vue swallows them, so the window listener never sees them.
  • swRoutes.ts is unchanged: its /api bypass already makes the telemetry routes network-only. A test pins that.

Bundle

The main chunk cannot keep its hash compared with main, because the client.ts hook and the loader live in the default bundle. With the toggle on or off the same build serves the same chunk (checked on the stack).

main this branch
entry chunk (gzip) 12,472 B 12,710 B
initial bundle 162.8 KB 163.2 KB
OpenTelemetry code in the initial bundle none none
otel-* chunk, loaded only when on n/a 27.8 KB gz

Docs

docs/operations/monitoring.md#frontend-telemetry-experimental covers the config, the relay, a Collector redaction processor snippet, what the UI sends, and the note that package bumps may change the data model. The generated reference docs are updated.

Verification

  • make test, make deadcode, make docs-gen and make docs-check pass, also after rebasing on feat(telemetry): count dropped OTLP log records and test against a real collector #304. make lint reports only pkg/rpm/dependencies.go:72 (nolintlint), which also fails on main with golangci-lint 2.13.2.
  • bun run generate-api, then bun run typecheck && bun test && bun run build (1724 pass), the bundle size check and jscpd pass.
  • Isolated stack -p oa-frontend-telemetry, otel-collector profile, file exporter, with the docs' redaction/frontend processor used verbatim:
    • relay: 401, 403 (token), 403 (no CSRF header), 413, 415, 404 (/metrics signal), 502 with the Collector stopped while other requests answered 200; the counter went up as expected
    • toggle off: both endpoints 404, no otel-* request, no traceparent
    • toggle on:
      • web vitals arrived as browser.web_vital (fcp, ttfb, cls, lcp)
      • UI errors arrived as exception with exception.type, .message and .stacktrace, from both the errors instrumentation and Vue's handler, all with service.name=openartifact-web and service.version=0.13.1
      • an API call produced one trace: browser HTTP GET client span → GET /api/v1/admin/audit server span → database spans
      • the redaction snippet masked ?token=secret&b=2

Experimental: no compatibility promise, no dashboards or alerts.

@gjed gjed self-assigned this Oct 28, 2026
@github-actions

github-actions Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Coverage

Coverage vs main
Go, unit + integration 80.5% ±0.0
Go, unit tests only 66.8% ±0.0
Go, integration tests only 57.0% +0.1
Web, lines 88.1% ±0.0
Web, functions 83.3% ±0.0
Go by area
Area Coverage vs main
cmd/docgen 82.2% ±0.0
cmd/genformats 86.4% ±0.0
cmd/oa 79.7% ±0.0
cmd/resetpw 0.0% ±0.0
cmd/server 71.3% ±0.0
internal/ai 87.2% ±0.0
internal/api 73.8% +0.1
internal/apkkeys 77.1% ±0.0
internal/attest 84.7% ±0.0
internal/audit 92.9% ±0.0
internal/auth 90.5% ±0.0
internal/backup 65.3% ±0.0
internal/bgtask 96.2% ±0.0
internal/branding 93.4% ±0.0
internal/clientsetup 94.2% ±0.0
internal/config 95.8% ±0.0
internal/cron 90.2% ±0.0
internal/crypto 90.7% ±0.0
internal/database 68.2% ±0.0
internal/declarative 75.5% ±0.0
internal/dtrack 85.1% ±0.0
internal/exploit 93.6% +0.3
internal/federation 81.1% +0.1
internal/format 77.6% ±0.0
internal/gpgkeys 87.3% +0.3
internal/group 89.2% ±0.0
internal/httpcache 100.0% ±0.0
internal/httpx 100.0% ±0.0
internal/importmeta 93.3% ±0.0
internal/iocopy 100.0% ±0.0
internal/license 99.4% ±0.0
internal/licensemeta 94.3% ±0.0
internal/licensepolicy 92.6% ±0.0
internal/mcp 87.5% ±0.0
internal/metrics 96.2% ±0.0
internal/middleware 93.6% ±0.0
internal/netutil 94.0% ±0.0
internal/nixkeys 79.6% ±0.0
internal/ocimanifest 100.0% ±0.0
internal/ocipath 100.0% ±0.0
internal/osv 84.1% ±0.0
internal/passwd 86.5% ±0.0
internal/pathseg 100.0% ±0.0
internal/pkgdeps 91.9% ±0.0
internal/presign 99.1% ±0.0
internal/promote 86.4% ±0.0
internal/proxy 86.1% ±0.0
internal/pypisimple 97.3% ±0.0
internal/quarantine 100.0% ±0.0
internal/quota 87.8% ±0.0
internal/recovery 84.7% -0.5
internal/replication 76.4% +0.1
internal/repodispatch 85.3% ±0.0
internal/repotype 95.5% ±0.0
internal/sbom 89.6% ±0.0
internal/scanexport 96.4% ±0.0
internal/search 90.6% ±0.0
internal/secrets 87.7% ±0.0
internal/storage 83.6% ±0.0
internal/telemetry 88.3% +0.6
internal/tiering 81.4% ±0.0
internal/trash 96.7% ±0.0
internal/urlparams 100.0% ±0.0
internal/vuln 89.0% +0.3
internal/webhook 82.3% ±0.0
internal/worker 82.5% +0.2
internal/xzutil 80.0% ±0.0
pkg/ansible 90.2% ±0.0
pkg/apk 96.0% ±0.0
pkg/cargo 95.3% ±0.0
pkg/compactindex 97.6% ±0.0
pkg/conan 99.2% ±0.0
pkg/conda 94.2% ±0.0
pkg/deb 76.1% ±0.0
pkg/delta 71.4% ±0.0
pkg/gemversion 100.0% ±0.0
pkg/gpg 86.7% ±0.0
pkg/helm 95.9% ±0.0
pkg/logger 93.8% ±0.0
pkg/maven 96.7% ±0.0
pkg/nix 99.1% ±0.0
pkg/npm 89.4% ±0.0
pkg/nuget 97.6% ±0.0
pkg/pacman 89.8% ±0.0
pkg/pyversion 100.0% ±0.0
pkg/rpm 91.8% ±0.0
pkg/rpmsign 90.5% ±0.0
pkg/rubymarshal 86.7% ±0.0
tests/integration 79.2% ±0.0
web 95.5% ±0.0
Web by area (lines)
Area Coverage vs main
src 23.5% ±0.0
src/api 88.9% +0.1
src/components 86.5% ±0.0
src/composables 91.8% ±0.0
src/i18n 96.5% ±0.0
src/lib 98.6% ±0.0
src/pages 87.9% ±0.0
src/pwa 98.8% ±0.0
src/router 99.3% ±0.0
src/stores 98.9% ±0.0
src/telemetry 90.5% new

Full report (HTML, merged profile) in the CI run artifacts

@gjed gjed left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

Reviewer is the PR author, so the review event is submitted as COMMENT.

Review effort: Deep
Findings: 1 High severity · 5 Medium severity

Open (6)
What changed in this PR

Adds experimental browser telemetry behind telemetry.frontend.enabled: a same-origin relay (POST /api/v1/telemetry/{traces,logs}) that forwards the UI's OTLP/HTTP exports to the Collector, a settings endpoint the UI reads after sign-in, and a lazily loaded OpenTelemetry web wrapper (errors, web vitals, one client span per API call) with traceparent propagation to the server.

Changes:

  • New telemetry.frontend.enabled / telemetry.frontend.endpoint settings with validation, env overrides, example configs and compose pass-through.
  • GET /api/v1/telemetry/frontend (404 while off) and the POST /api/v1/telemetry/{signal} relay (session-only, protobuf-only, 1 MiB cap, 10 s timeout), with an RBAC self-service rule, no audit row and the openartifact_frontend_telemetry_requests_total counter.
  • web/src/api/client.ts starts a client span per call and sends traceparent; web/src/telemetry loads the otel-* chunk only when the server reports the feature on, and the service worker does not precache it.
  • Seven OpenTelemetry packages pinned to exact versions in web/package.json and asserted against bun.lock.
  • Docs, OpenAPI spec, generated API client and generated reference docs updated.
File Description
internal/api/frontend_telemetry.go Config endpoint, relay handler, forwarding and result counter
internal/telemetry/config.go, internal/config/telemetry.go, internal/config/config.go FrontendConfig, FrontendActive, FrontendURL, validation and env overrides
internal/middleware/rbac.go, internal/middleware/audit.go Self-service access for the telemetry routes; relay excluded from the audit log
internal/metrics/metrics.go openartifact_frontend_telemetry_requests_total{signal,result}
cmd/server/app_routes.go, cmd/server/app_startup.go Route registration; startup log and warning without telemetry.otlp.enabled
internal/api/openapi.json, web/src/api/generated/*, docs/reference/* New operations and schema, regenerated client and reference docs
web/src/api/client.ts, web/src/api/telemetry.ts Client span factory, traceparent header, settings request
web/src/telemetry/index.ts, web/src/telemetry/otel.ts, web/src/main.ts On-demand loader, OpenTelemetry wrapper, Vue error handler hook and sign-in watcher
web/vite.pwa.ts, web/package.json, web/bun.lock otel-* chunk kept out of the precache; pinned dependencies
docs/operations/monitoring.md, .env.example, docker/*, openartifact.example.yaml Frontend telemetry docs and config examples
*_test.go, web/src/**/__tests__/* Relay status matrix, config validation, RBAC, audit, client span and pin tests

Comment thread internal/api/openapi.json Resolved
Comment thread internal/api/frontend_telemetry.go Resolved
Comment thread internal/api/frontend_telemetry.go Resolved
Comment thread web/src/main.ts Resolved
Comment thread docs/operations/monitoring.md Resolved
Comment thread web/bun.lock Resolved

@M0Rf30 M0Rf30 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the design is solid: off by default (404 + no SDK load), session-only relay with CSRF, body and content-type limits, config-only destination with no credential passthrough, no URL/user data in client spans, same-origin traceparent, exact pins behind one module, good tests.

Blocking:

  • api-fuzz fails (run 40690782714): Schemathesis cannot serialize the application/x-protobuf body of POST /api/v1/telemetry/{signal} ("No supported serializers"). Register a binary serializer for that media type in tests/apifuzz/hooks.py, or exclude the operation in tests/apifuzz/schemathesis.toml with a comment. Every other case passes.

Please also address:

  1. internal/api/frontend_telemetry.go (~83): the relay client follows redirects, so a collector redirect would replay otlp.headers (e.g. an API key) to the redirect target. Set CheckRedirect to return http.ErrUseLastResponse.
  2. Error events send exception.message and exception.stacktrace unredacted; the docs point operators to a Collector redaction processor, but docker/otel-collector.yaml (used by Compose, where the endpoint defaults to the bundled collector) has none. Add the processor there so enabling the toggle in Compose doesn't export raw stack traces.

Nits:
3. No concurrency cap on the relay; bounded by the global rate limit and session requirement, but a small semaphore is cheap.
4. A one-line comment that the relay deliberately doesn't use the SSRF-safe client (collectors are usually internal).

@gjed

gjed commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor Author

@M0Rf30 all points are addressed, pushed next:

  • api-fuzz: the relay is excluded in tests/apifuzz/schemathesis.toml with a reason, b0c44cf.
  • Redirects: CheckRedirect now refuses them, with a test that a 307 answers 502, dc47bf5.
  • Redaction: redaction/frontend is on the traces and logs pipelines of docker/otel-collector.yaml, checked with the pinned collector image, 80b3ad9.
  • Concurrency: at most 32 forwards in flight, then 503 with Retry-After, 866c7dd.
  • SSRF client: comment added in dc47bf5.

@gjed
gjed requested a review from M0Rf30 October 28, 2026 15:52
@gjed
gjed marked this pull request as ready for review October 28, 2026 16:31

@M0Rf30 M0Rf30 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, all four points are resolved: the api-fuzz exclusion is scoped to POST /api/v1/telemetry/{signal} with the reason; redirects answer 502 with a test proving the target gets nothing; redaction/frontend is wired into the traces and logs pipelines and masks query strings in exception text; the in-flight cap answers 503 relay_busy before reading the body. Not tracing the relay and the untrusted-data note are good additions.

Before merging, please rebase on main: it conflicts in internal/metrics/metrics.go (keep both sets of additions) and web/src/api/generated/index.ts (regenerate with bun run generate-api, don't hand-merge).

Non-blocking: redaction only masks key=value query fragments (tokens in paths or free text pass; the docs say best effort, fine); isProbe now reads better as untraced.

gjed added 13 commits October 28, 2026 21:12
…dpoint

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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
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.
@gjed
gjed force-pushed the feat/frontend-telemetry branch from 9e6de3e to 8e10229 Compare October 28, 2026 21:01
It also covers the frontend telemetry relay's exports, which are not
probes. Name it for what it decides and document it.
@M0Rf30
M0Rf30 merged commit bbe41c8 into main Oct 29, 2026
20 checks passed
@M0Rf30
M0Rf30 deleted the feat/frontend-telemetry branch October 29, 2026 11:15
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]>
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.

Telemetry: experimental frontend telemetry (OTel JS) behind a same-origin relay

2 participants