feat: add OTEL instrumentation for authentication and handlers#25296
feat: add OTEL instrumentation for authentication and handlers#25296agaudreault merged 5 commits intoargoproj:masterfrom
Conversation
❌ Preview Environment deleted from BunnyshellAvailable commands (reply to this comment):
|
dcc37c2 to
9221027
Compare
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #25296 +/- ##
==========================================
+ Coverage 62.49% 62.52% +0.02%
==========================================
Files 351 351
Lines 49602 49697 +95
==========================================
+ Hits 31001 31072 +71
- Misses 15631 15655 +24
Partials 2970 2970 ☔ View full report in Codecov by Sentry. |
|
Could you share the snapshot of metrics on a visualization tool? |
|
I thought it would be Jaeger, since I worked on OTEL instrumentation part. 😄 Thanks for sharing those. |
562fd91 to
c6045b3
Compare
* Add OTEL tracer initialization in server, session, oidc packages * Add span creation to all methods for tracing authentication flow with SSO * Wrap HTTP handlers with otelhttp.NewHandler to capture the root span * Add error status and attributes to spans' * Capture cache read/write timing Signed-off-by: Mike Cutsail <mcutsail15@apple.com>
c6045b3 to
6549613
Compare
server/server.go
Outdated
| // OIDC tokens will be verified but will not be refreshed here. | ||
| claims, newToken, err := server.sessionMgr.VerifyToken(ctx, tokenString) | ||
| if err != nil { | ||
| span.SetAttributes(attribute.String("token", tokenString)) |
There was a problem hiding this comment.
I dont think we should add the token here.
| span.SetAttributes(attribute.String("token", tokenString)) |
util/oidc/oidc.go
Outdated
| // GetTokenSourceFromCache creates an oauth2 TokenSource from a cached oidc token. The TokenSource will be configured | ||
| // with an early expiration based on the refreshTokenThreshold. | ||
| func (a *ClientApp) GetTokenSourceFromCache(ctx context.Context, oidcTokenCache *OidcTokenCache) (oauth2.TokenSource, error) { | ||
| spanCtx, span := tracer.Start(ctx, "oidc.ClientApp.GetTokenSourceFromCache") |
There was a problem hiding this comment.
Afaik, it is good practice to just overwrite the ctx.
| spanCtx, span := tracer.Start(ctx, "oidc.ClientApp.GetTokenSourceFromCache") | |
| ctx, span = tracer.Start(ctx, "oidc.ClientApp.GetTokenSourceFromCache") |
util/oidc/oidc.go
Outdated
| span.SetAttributes( | ||
| attribute.String("network", network), | ||
| attribute.String("addr", addr), | ||
| ) | ||
| defer span.End() |
There was a problem hiding this comment.
defer as close as possible
| span.SetAttributes( | |
| attribute.String("network", network), | |
| attribute.String("addr", addr), | |
| ) | |
| defer span.End() | |
| defer span.End() | |
| span.SetAttributes( | |
| attribute.String("network", network), | |
| attribute.String("addr", addr), | |
| ) |
util/oidc/oidc.go
Outdated
| defer span.End() | ||
|
|
||
| ctx = gooidc.ClientContext(ctx, a.client) | ||
| if span.IsRecording() { |
There was a problem hiding this comment.
I dont think there is any performance need to use IsRecording func here. Correct me if I am wrong, but this is in case expensive operation needs to be done to set the attributes.
go.mod
Outdated
| sigs.k8s.io/yaml v1.6.0 | ||
| ) | ||
|
|
||
| require ( |
There was a problem hiding this comment.
Move to the common require section
Signed-off-by: Mike Cutsail <mcutsail15@apple.com>
Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
…roj#25296) Signed-off-by: Mike Cutsail <mcutsail15@apple.com> Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>
…roj#25296) Signed-off-by: Mike Cutsail <mcutsail15@apple.com> Signed-off-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com> Co-authored-by: Alexandre Gaudreault <alexandre_gaudreault@intuit.com>






Follow up to #23727, improving observability for the OIDC authentication flow:
Checklist: