@@ -29,6 +29,7 @@ export class SpiceDBAuthorizer {
29
29
if ( ! this . client ) {
30
30
return true ;
31
31
}
32
+ const timing = startTimer ( ) ;
32
33
33
34
const featureEnabled = await getExperimentsClientForBackend ( ) . getValueAsync ( "centralizedPermissions" , false , {
34
35
user : {
@@ -54,13 +55,15 @@ export class SpiceDBAuthorizer {
54
55
return false ;
55
56
} finally {
56
57
observeSpicedbClientLatency ( "check" , error , timer ( ) ) ;
58
+ stopTimer ( "CHECK" , timing ) ;
57
59
}
58
60
}
59
61
60
62
async writeRelationships ( ...updates : v1 . RelationshipUpdate [ ] ) : Promise < v1 . WriteRelationshipsResponse | undefined > {
61
63
if ( ! this . client ) {
62
64
return undefined ;
63
65
}
66
+ const timing = startTimer ( ) ;
64
67
65
68
const timer = spicedbClientLatency . startTimer ( ) ;
66
69
let error : Error | undefined ;
@@ -78,13 +81,15 @@ export class SpiceDBAuthorizer {
78
81
log . error ( "[spicedb] Failed to write relationships." , err , { updates : new TrustedValue ( updates ) } ) ;
79
82
} finally {
80
83
observeSpicedbClientLatency ( "write" , error , timer ( ) ) ;
84
+ stopTimer ( "WRITE" , timing ) ;
81
85
}
82
86
}
83
87
84
88
async deleteRelationships ( req : v1 . DeleteRelationshipsRequest ) : Promise < v1 . ReadRelationshipsResponse [ ] > {
85
89
if ( ! this . client ) {
86
90
return [ ] ;
87
91
}
92
+ const timing = startTimer ( ) ;
88
93
89
94
const timer = spicedbClientLatency . startTimer ( ) ;
90
95
let error : Error | undefined ;
@@ -111,6 +116,7 @@ export class SpiceDBAuthorizer {
111
116
return [ ] ;
112
117
} finally {
113
118
observeSpicedbClientLatency ( "delete" , error , timer ( ) ) ;
119
+ stopTimer ( "DELETE" , timing ) ;
114
120
}
115
121
}
116
122
@@ -121,3 +127,11 @@ export class SpiceDBAuthorizer {
121
127
return this . client . readRelationships ( req ) ;
122
128
}
123
129
}
130
+ function startTimer ( ) {
131
+ return process . hrtime ( ) ;
132
+ }
133
+
134
+ function stopTimer ( method : string , hrtime : [ number , number ] ) {
135
+ const seconds = ( hrtime [ 0 ] + hrtime [ 1 ] / 1e6 ) . toFixed ( 3 ) ;
136
+ log . info ( `[SPICEDB] ${ method } (${ seconds } ms)` ) ;
137
+ }
0 commit comments