1818package user
1919
2020import (
21+ "context"
2122 "fmt"
2223 "github.com/devtron-labs/authenticator/jwt"
2324 "github.com/devtron-labs/authenticator/middleware"
@@ -31,6 +32,7 @@ import (
3132 util2 "github.com/devtron-labs/devtron/util"
3233 "github.com/go-pg/pg"
3334 "github.com/gorilla/sessions"
35+ "go.opentelemetry.io/otel"
3436 "go.uber.org/zap"
3537 "net/http"
3638 "strings"
@@ -50,7 +52,7 @@ type UserService interface {
5052 DeleteUser (userInfo * bean.UserInfo ) (bool , error )
5153 CheckUserRoles (id int32 ) ([]string , error )
5254 SyncOrchestratorToCasbin () (bool , error )
53- GetUserByToken (token string ) (int32 , string , error )
55+ GetUserByToken (context context. Context , token string ) (int32 , string , error )
5456 IsSuperAdmin (userId int ) (bool , error )
5557 GetByIdIncludeDeleted (id int32 ) (* bean.UserInfo , error )
5658 UserExists (emailId string ) bool
@@ -1159,26 +1161,29 @@ func (impl UserServiceImpl) GetUserByEmail(emailId string) (*bean.UserInfo, erro
11591161 return response , nil
11601162}
11611163func (impl UserServiceImpl ) GetLoggedInUser (r * http.Request ) (int32 , error ) {
1164+ _ , span := otel .Tracer ("userService" ).Start (r .Context (), "GetLoggedInUser" )
1165+ defer span .End ()
11621166 token := ""
11631167 if strings .Contains (r .URL .Path , "/orchestrator/webhook/ext-ci/" ) {
11641168 token = r .Header .Get ("api-token" )
11651169 } else {
11661170 token = r .Header .Get ("token" )
11671171 }
1168- userId , userType , err := impl .GetUserByToken (token )
1172+ userId , userType , err := impl .GetUserByToken (r . Context (), token )
11691173 // if user is of api-token type, then update lastUsedBy and lastUsedAt
11701174 if err == nil && userType == bean .USER_TYPE_API_TOKEN {
11711175 go impl .saveUserAudit (r , userId )
11721176 }
11731177 return userId , err
11741178}
11751179
1176- func (impl UserServiceImpl ) GetUserByToken (token string ) (int32 , string , error ) {
1180+ func (impl UserServiceImpl ) GetUserByToken (context context.Context , token string ) (int32 , string , error ) {
1181+ _ , span := otel .Tracer ("userService" ).Start (context , "GetUserByToken" )
11771182 email , err := impl .GetEmailFromToken (token )
1183+ span .End ()
11781184 if err != nil {
11791185 return http .StatusUnauthorized , "" , err
11801186 }
1181-
11821187 userInfo , err := impl .GetUserByEmail (email )
11831188 if err != nil {
11841189 impl .logger .Errorw ("unable to fetch user from db" , "error" , err )
0 commit comments