@@ -17,11 +17,13 @@ use mas_storage::{
17
17
oauth2:: OAuth2SessionFilter ,
18
18
} ;
19
19
use oauth2_types:: scope:: { Scope , ScopeToken } ;
20
+ use opentelemetry_semantic_conventions:: trace:: DB_QUERY_TEXT ;
20
21
use sea_query:: {
21
22
Alias , ColumnRef , CommonTableExpression , Expr , PostgresQueryBuilder , Query , UnionType ,
22
23
} ;
23
24
use sea_query_binder:: SqlxBinder ;
24
25
use sqlx:: PgConnection ;
26
+ use tracing:: Instrument ;
25
27
use ulid:: Ulid ;
26
28
use uuid:: Uuid ;
27
29
@@ -478,7 +480,10 @@ impl AppSessionRepository for PgAppSessionRepository<'_> {
478
480
device : & Device ,
479
481
) -> Result < ( ) , Self :: Error > {
480
482
// TODO need to invoke this from all the oauth2 login sites
481
- // TODO CREATE A SECOND SPAN FOR THE SECOND QUERY
483
+ let span = tracing:: info_span!(
484
+ "db.app_session.finish_sessions_to_replace_device.compat_sessions" ,
485
+ { DB_QUERY_TEXT } = tracing:: field:: Empty ,
486
+ ) ;
482
487
let finished_at = clock. now ( ) ;
483
488
sqlx:: query!(
484
489
"
@@ -488,11 +493,16 @@ impl AppSessionRepository for PgAppSessionRepository<'_> {
488
493
device. as_str( ) ,
489
494
finished_at
490
495
)
491
- . traced ( )
496
+ . record ( & span )
492
497
. execute ( & mut * self . conn )
498
+ . instrument ( span)
493
499
. await ?;
494
500
495
501
if let Ok ( device_as_scope_token) = device. to_scope_token ( ) {
502
+ let span = tracing:: info_span!(
503
+ "db.app_session.finish_sessions_to_replace_device.oauth2_sessions" ,
504
+ { DB_QUERY_TEXT } = tracing:: field:: Empty ,
505
+ ) ;
496
506
sqlx:: query!(
497
507
"
498
508
UPDATE oauth2_sessions SET finished_at = $3 WHERE user_id = $1 AND $2 = ANY(scope_list) AND finished_at IS NULL
@@ -501,8 +511,9 @@ impl AppSessionRepository for PgAppSessionRepository<'_> {
501
511
device_as_scope_token. as_str( ) ,
502
512
finished_at
503
513
)
504
- . traced ( )
514
+ . record ( & span )
505
515
. execute ( & mut * self . conn )
516
+ . instrument ( span)
506
517
. await ?;
507
518
}
508
519
0 commit comments