Skip to content

Trace the API credential on REST requests - #6907

Merged
vinibrsl merged 4 commits into
masterfrom
otel/shared-attributes
Nov 23, 2026
Merged

vinibrsl merged 4 commits into
masterfrom
otel/shared-attributes

Conversation

@vinibrsl

@vinibrsl vinibrsl commented Nov 20, 2026 •

Copy link
Copy Markdown
Member

Changes

OTEL traces of Stats and Sites API requests did not say who sent them. This PR adds the credential attributes to the HTTP server span:

  • plausible.user.id
  • plausible.team.id
  • plausible.credential.type
  • plausible.credential.id
  • plausible.credential.label

Tests

  • Automated tests have been added

Changelog

  • This PR does not make a user-facing change

Documentation

  • This change does not need a documentation update

Dark mode

  • This PR does not change the UI

Tests could not assert on trace attributes because no span was recorded.

This commit sets up OTel tests as in the [official guide](https://opentelemetry.io/docs/languages/erlang/testing/):
a simple processor with no exporter, no `sampler: :always_off` in tests,
and the `OpentelemetryPhoenix` `endpoint_start` handler detached. In
`ConnTest`, that handler replaced the test's trace context.

Recording spans has no measurable cost. Full `mix test`, same seed:
290s and 292s with spans, 302s and 292s without.
Traces of Stats and Sites API requests did not say who sent them.

`AuthorizePublicAPI` now sets the user, team, credential type and
credential ID right after the key lookup, so rate-limited requests carry
them too. Like the API request log (#6881), the attributes work for any
credential with a user and a team.

Legacy keys have no team, so we use the team of the verified site.
This commit moves the trace test to `PlausibleWeb.APITraceAttributesTest`
and covers rate-limited requests, legacy keys and the Sites API.

It also sets the site attributes on Sites API requests with a `site_id`,
like the Stats API does.
Set `plausible.credential.label` with the same value as `credential_label`
in the API request log. For an API key this is the key prefix. One attribute
names the caller for every credential type, so traces need no separate
attribute per credential, such as the OAuth client ID.
@vinibrsl
vinibrsl added this pull request to stack #6908 November 20, 2026 22:59
@vinibrsl
vinibrsl requested a review from a team November 23, 2026 12:44
@vinibrsl
vinibrsl added this pull request to the merge queue Nov 23, 2026
Merged via the queue into master with commit 0798187 Nov 23, 2026
30 checks passed
@vinibrsl
vinibrsl deleted the otel/shared-attributes branch November 23, 2026 15:38
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.

2 participants