feat(telemetry): opt-in product telemetry relay and per-tenant switch #148
Open
sharang
wants to merge 1 commits from
feat/telemetry-relay into main
pull from: feat/telemetry-relay
merge into: platform:main
platform:main
platform:feat/einstieg-plan
platform:feat/update-policy
platform:feat/feedback-endpoint
platform:feat/onprem
platform:feat/onprem-mail
platform:feat/onprem-directory-users
platform:feat/onprem-mode
platform:feat/avv-autofill
platform:feat/release-avv-1.0.0
platform:fix/erpsetup-dunning-and-small
platform:feat/module-user-count
platform:feat/usage-summary
platform:feat/mahnung-ladder
platform:fix/toms-status-available
platform:feat/contractdocs-agb-tom
platform:feat/company-rules
platform:feat/staff-brand-slug
platform:fix/intake-outlives-purge
platform:fix/catalogue-labels
platform:feat/trial-offer-status
platform:feat/function-holders
platform:feat/assignable-bundles
platform:feat/contract-documents
platform:feat/erp-lb-versions
platform:feat/store-merges-unterlagen
platform:feat/product-hierarchy
platform:feat/preview-grants
platform:ci/platform-image-and-webhook
platform:ci/registry-meghsakha-orca-webhook
No Reviewers
Dismiss Review
Are you sure you want to dismiss this review?
Labels
Clear labels
cra:annex-i
cve
pruefwerk
risk:accepted
severity:critical
severity:high
severity:low
severity:medium
CRA Anhang I, wesentliche Cybersicherheitsanforderungen / CRA Annex I
Bekannte Schwachstelle in einer Abhängigkeit / known vulnerability in a dependency
Befund aus Prüfwerk / Prüfwerk finding
Risiko akzeptiert, nicht behoben / accepted risk, not fixed
Schweregrad kritisch / critical
Schweregrad hoch / high
Schweregrad niedrig / low
Schweregrad mittel / medium
No labels
Milestone
No items
No Milestone
Projects
Clear projects
No projects
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: platform/tenant-registry#148
Reference in new issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
What
The server half of opt-in, content-free telemetry (platform/werkpilot#87).
GET/PUT /v1/tenants/{id}/products/{product}/telemetry.telemetryboolean in the licence grants and the heartbeat, so the CLI knows the switch.POST /v1/telemetryrelay. It checks a batch against a fixed allowlist and forwards it to the collector as OTLP/HTTP JSON. No ingest token ever sits on a customer machine.Why
Refs platform/werkpilot#87. The agreed design:
The licence-client and werkpilot sides are built in parallel against this contract.
Linked milestone: n/a (werkpilot#87)
How
Setting
telemetrykey of the product'stenant_product_settingsdocument (0025), so no migration. The PUT reads the document, sets the key and writes it back; other keys survive (tested).werkpilot, others 404. The Prüfwerk settings PUT replaces its whole document, so the key must never land there.PUT {"enabled": true|false}(exactly that body, else 400) answers{tenant_id, product, enabled, updated_by, updated_at}.FORBIDDEN_ROLE; another workspace gets 404). Services usetenants.read/tenants.write; the portal calls as its service client, as for the Prüfwerk settings.product_settings.changed(setting: telemetry, old, new). A save that changes nothing writes nothing.Flag in the licence answers
telemetry(always present, default false) is a plain JSON field in the grant ofPOST /v1/licences,POST /v1/licences/ciand therenewedgrant of a heartbeat. It is not a JWT claim.status, read fresh on every call. It is false on therevoked/ unknown-tenant answers.Relay
POST /v1/telemetrytelemetry_unavailablewithout a token.user_token_requiredfor anything but a user token.too_large).telemetry_disabledand nothing is forwarded.invalid_input, naming the metric index and name, or the key).metricslist answers 204 and forwards nothing.rate_limited): 120 per user subject per sliding hour, in memory. Refused and empty batches don't count.telemetry_failed.^[A-Za-z0-9_.:-]{1,64}$.countandbucket_countsmust be JSON integer literals ≥ 0, so-1,1.5,3.0,1e3and"3"are refused.sumis a number ≥ 0. At most 20 bounds, andlen(bounds)+1bucket counts.TELEMETRY_OTLP_URLwithAuthorization: Bearer <TELEMETRY_OTLP_TOKEN>.service.name(product),service.version,tenant.slug,tenant.id,deployment.environment(APP_ENV).startTimeUnixNano/timeUnixNanofrom the interval.telemetry. A user token from a client holdinglicences(todaywerkpilot-cli,firmwerk-cli) passes without it, so the deployed AUTHZ_RULES need no change. A sign-in client withoutlicencesand a service token holdinglicencesare refused (FORBIDDEN_CLIENT).POST /v1/usage/eventsit emits none; 120 batches per person and hour would flood the tenant's log. Only the setting change is audited.TELEMETRY_OTLP_TOKENset,TELEMETRY_OTLP_URLmust be given explicitly, mirroring LiteLLM.internal/otlp: the export builder and client.go.opentelemetry.io/proto/otlpandgoogle.golang.org/protobufmove from indirect to direct ingo.mod(same versions, no new modules,go.sumunchanged). They are used only in a test, to check the forwarded body against the OTLP protobuf JSON mapping.Stricter than #87 (declared in the spec):
versionis the only free-text field that is forwarded. It is constrained to^[A-Za-z0-9.+_-]{1,64}$, which covers semver with pre-release and build parts.boundsmust be strictly increasing, as OTLP requires.countequals the sum ofbucket_counts.Overlap with #147 (feedback): both PRs edit the same spots: the
requireAuthzexception, therouteGroupswitch, theServerstruct, the route block, the config/README/onprem lists and the spec. Whichever merges second gets textual conflicts to resolve (keep both). No identifiers are shared, so the merged code compiles once the conflicts are resolved.Going live (orca, not in this PR)
After merge and deploy, the relay answers 503 until:
TELEMETRY_OTLP_TOKENis added to the collector'sbearertokenauth/ingesttoken list in orca-infra, and the same value to the registry's deployment secret (platform-stage/platform-prod).PUT /v1/tenants/{id}/products/werkpilot/telemetry {"enabled":true}; until the portal toggle exists, through the portal's service client or staff).No tokens were created for this PR.
Test plan
telemetry_relay_test.go, fake collector):isMonotonic), the bearer header and path. The same bytesprotojson.UnmarshalintoExportMetricsServiceRequest(temporality, monotonic, values, bucket counts, interval), and neither the subject nor the e-mail is present.telemetry_disabled: for a tenant never enabled, one turned off, and when the body names another tenant. Nothing is forwarded.werkpilot-cliandfirmwerk-cliuser tokens with the deployed rules, plus a client grantedtelemetry. A sign-in client withoutlicences, alicencesservice token and a missing principal are refused.licence_telemetry_test.go, througheachStore):authz_testroute groups,openapi_testroute cases, config defaults and the on-prem refusal.gofmt -l .clean,go vet ./...clean,golangci-lint run(v2.12.2) 0 issues,go test -race -count=1 ./...green.eachStorePostgres variants skipped locally (Docker is unreachable here), so they run only in CI. The store calls are the existingGetTenantProductSettings/PutTenantProductSettings/AppendAudit.Risk
Blast radius:
What could break:
Rollback plan:
TELEMETRY_OTLP_TOKEN(503).Checklist
product_settings.changed; relay batches not audited, see How)TELEMETRY_OTLP_TOKENis a deployment secret)featureFlags.evaluate()used for any toggleable behavior: n/a, the per-tenant switch is stored data and the token's presence turns the relay onScreenshots / recordings
n/a (no UI; the portal toggle is a follow-up)
🤖 Generated with Claude Code
https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPR
Werkpilot's content-free usage metrics go through the registry, so no collector token sits on customer machines, and only for workspaces that turned telemetry on. - GET/PUT /v1/tenants/{id}/products/{product}/telemetry: the switch, default off, kept as the "telemetry" key of the product's settings document (0025, no migration); IT_ADMIN/OWNER or services; audited as product_settings.changed - "telemetry" in licence grants (POST /v1/licences, /v1/licences/ci, heartbeat renewals) and at the top of the heartbeat answer - POST /v1/telemetry: checks a batch against a fixed allowlist and forwards it to TELEMETRY_OTLP_URL as OTLP/HTTP JSON (delta sums and histograms, tenant resource attributes, never the person); 120 batches per person and hour; CLI user tokens pass with their licences grant Refs platform/werkpilot#87 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Q9inRayW7ztyk1uAtwMJPRView command line instructions
Checkout
From your project repository, check out a new branch and test the changes.