Repository navigation
Trace the API credential on REST requests - #6907
Merged
Merged
Conversation
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.
RobertJoonas
approved these changes
Nov 23, 2026
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.
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.idplausible.team.idplausible.credential.typeplausible.credential.idplausible.credential.labelTests
Changelog
Documentation
Dark mode