@@ -165,7 +165,7 @@ func (a *AsyncRecorder) RecordInterceptionEnded(ctx context.Context, req *Interc
165165 a .wg .Add (1 )
166166 go func () {
167167 defer a .wg .Done ()
168- timedCtx , cancel := a . timedContext ( ctx )
168+ timedCtx , cancel := context . WithTimeout ( context . WithoutCancel ( ctx ), a . timeout )
169169 defer cancel ()
170170
171171 err := a .wrapped .RecordInterceptionEnded (timedCtx , req )
@@ -181,7 +181,7 @@ func (a *AsyncRecorder) RecordPromptUsage(ctx context.Context, req *PromptUsageR
181181 a .wg .Add (1 )
182182 go func () {
183183 defer a .wg .Done ()
184- timedCtx , cancel := a . timedContext ( ctx )
184+ timedCtx , cancel := context . WithTimeout ( context . WithoutCancel ( ctx ), a . timeout )
185185 defer cancel ()
186186
187187 err := a .wrapped .RecordPromptUsage (timedCtx , req )
@@ -201,7 +201,7 @@ func (a *AsyncRecorder) RecordTokenUsage(ctx context.Context, req *TokenUsageRec
201201 a .wg .Add (1 )
202202 go func () {
203203 defer a .wg .Done ()
204- timedCtx , cancel := a . timedContext ( ctx )
204+ timedCtx , cancel := context . WithTimeout ( context . WithoutCancel ( ctx ), a . timeout )
205205 defer cancel ()
206206
207207 err := a .wrapped .RecordTokenUsage (timedCtx , req )
@@ -225,7 +225,7 @@ func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecor
225225 a .wg .Add (1 )
226226 go func () {
227227 defer a .wg .Done ()
228- timedCtx , cancel := a . timedContext ( ctx )
228+ timedCtx , cancel := context . WithTimeout ( context . WithoutCancel ( ctx ), a . timeout )
229229 defer cancel ()
230230
231231 err := a .wrapped .RecordToolUsage (timedCtx , req )
@@ -252,10 +252,3 @@ func (a *AsyncRecorder) RecordToolUsage(ctx context.Context, req *ToolUsageRecor
252252func (a * AsyncRecorder ) Wait () {
253253 a .wg .Wait ()
254254}
255-
256- // returns detrached context with tracing information copied from provided context
257- func (a * AsyncRecorder ) timedContext (ctx context.Context ) (context.Context , context.CancelFunc ) {
258- timedCtx , cancel := context .WithTimeout (context .Background (), a .timeout )
259- timedCtx = aibtrace .WithTraceInterceptionAttributesInContext (timedCtx , aibtrace .TraceInterceptionAttributesFromContext (ctx ))
260- return timedCtx , cancel
261- }
0 commit comments