Skip to content

feat: Add authenticated environment attributes to relay.auth span and metrics - #781

Open
keelerm84 wants to merge 2 commits into
v9from
mk/SDK-2774/add-env-attribute
Open

feat: Add authenticated environment attributes to relay.auth span and metrics#781
keelerm84 wants to merge 2 commits into
v9from
mk/SDK-2774/add-env-attribute

Conversation

@keelerm84

@keelerm84 keelerm84 commented Jul 29, 2026

Copy link
Copy Markdown
Member

Summary

Emit the authenticated environment as telemetry attributes so traces and metrics can be correlated by environment.

  • relay.auth span: on successful auth, both auth middlewares now set relay.auth.environment.name (always, the human-readable display name) and relay.auth.environment.id (only when an EnvironmentID credential is configured). The relay.auth.result=success attribute remains unconditional.
  • Metrics: the per-environment attribute set keeps the existing environment.name and now also emits environment.id when available.

The environment ID may be absent for SDK-key-only environments in a manual configuration, so it is only added when present.


Note

Low Risk
Additive telemetry and an internal metrics API signature change; no auth or request-handling behavior changes beyond extra span attributes.

Overview
Adds environment identity to OpenTelemetry so traces and per-environment metrics can be correlated beyond display name alone.

On successful auth, both SelectEnvironmentByAuthorizationKey and SelectEnvironmentByClientSideAuth set relay.auth.environment.name (display name) and, when configured, relay.auth.environment.id on the relay.auth span via a shared authEnvSpanAttributes helper. environment.id is omitted for SDK-key-only manual configs where no environment ID exists.

Metrics extend Manager.AddEnvironment with an envID argument; the environment attribute set still includes environment.name and now adds environment.id when non-empty. Environment startup passes envConfig.EnvID from env_context_impl.

Tests cover presence/absence of environment.id on metric attributes; existing AddEnvironment call sites pass an empty ID where appropriate.

Reviewed by Cursor Bugbot for commit 70b8963. Bugbot is set up for automated code reviews on this repo. Configure here.

@keelerm84
keelerm84 changed the base branch from v8 to v9 July 29, 2026 18:36
@keelerm84
keelerm84 marked this pull request as ready for review July 30, 2026 15:43
@keelerm84
keelerm84 requested a review from a team as a code owner July 30, 2026 15:43
Comment thread internal/middleware/middleware.go
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