Skip to content

Commit e724696

Browse files
committed
fix: #633 fix a bug where tracingDisabled in realtime config does not work
1 parent 14016fd commit e724696

File tree

6 files changed

+49
-3
lines changed

6 files changed

+49
-3
lines changed

.changeset/fuzzy-seas-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@openai/agents-realtime': patch
3+
---
4+
5+
fix: #633 fix a bug where tracingDisabled in realtime config does not work

packages/agents-realtime/src/openaiRealtimeBase.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ export abstract class OpenAIRealtimeBase
672672
*
673673
* @param tracingConfig - The tracing config to set. We don't support 'auto' here as the SDK will always configure a Workflow Name unless it exists
674674
*/
675-
protected _updateTracingConfig(tracingConfig: RealtimeTracingConfig) {
675+
protected _updateTracingConfig(tracingConfig: RealtimeTracingConfig | null) {
676676
if (typeof this.#tracingConfig === 'undefined') {
677677
// treating it as default value
678678
this.#tracingConfig = null;

packages/agents-realtime/src/openaiRealtimeWebRtc.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,11 @@ export class OpenAIRealtimeWebRTC
245245
if (parsed.type === 'session.created') {
246246
this._tracingConfig = parsed.session.tracing;
247247
// Trying to turn on tracing after the session is created
248-
this._updateTracingConfig(userSessionConfig.tracing ?? 'auto');
248+
const tracingConfig =
249+
typeof userSessionConfig.tracing === 'undefined'
250+
? 'auto'
251+
: userSessionConfig.tracing;
252+
this._updateTracingConfig(tracingConfig);
249253
}
250254
});
251255

packages/agents-realtime/src/openaiRealtimeWebsocket.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,11 @@ export class OpenAIRealtimeWebSocket
308308
} else if (parsed.type === 'session.created') {
309309
this._tracingConfig = parsed.session.tracing;
310310
// Trying to turn on tracing after the session is created
311-
this._updateTracingConfig(sessionConfig.tracing ?? 'auto');
311+
const tracingConfig =
312+
typeof sessionConfig.tracing === 'undefined'
313+
? 'auto'
314+
: sessionConfig.tracing;
315+
this._updateTracingConfig(tracingConfig);
312316
}
313317
});
314318

packages/agents-realtime/src/realtimeSession.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,8 @@ export class RealtimeSession<
350350
this.#context,
351351
);
352352

353+
// Realtime expects tracing to be explicitly null to disable it; leaving the previous config
354+
// in place would otherwise continue emitting spans.
353355
const tracingConfig: RealtimeTracingConfig | null = this.options
354356
.tracingDisabled
355357
? null

packages/agents-realtime/test/openaiRealtimeWebsocket.test.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,37 @@ describe('OpenAIRealtimeWebSocket', () => {
194194
expect(() => ws.mute(true)).toThrow('Mute is not supported');
195195
});
196196

197+
it('disables tracing when initial config sets tracing to null', async () => {
198+
const updateSpy = vi.spyOn(
199+
OpenAIRealtimeBase.prototype as any,
200+
'_updateTracingConfig',
201+
);
202+
const ws = new OpenAIRealtimeWebSocket();
203+
const connectPromise = ws.connect({
204+
apiKey: 'ek',
205+
model: 'm',
206+
initialSessionConfig: {
207+
tracing: null,
208+
},
209+
});
210+
await vi.runAllTimersAsync();
211+
await connectPromise;
212+
213+
lastFakeSocket!.emit('message', {
214+
data: JSON.stringify({
215+
type: 'session.created',
216+
event_id: 'evt_1',
217+
session: {
218+
tracing: 'auto',
219+
},
220+
}),
221+
});
222+
223+
expect(updateSpy).toHaveBeenCalled();
224+
const lastCall = updateSpy.mock.calls.at(-1);
225+
expect(lastCall?.[0]).toBeNull();
226+
});
227+
197228
it('sendAudio only sends when connected', async () => {
198229
const baseSpy = vi.spyOn(OpenAIRealtimeBase.prototype, 'sendAudio');
199230
const ws = new OpenAIRealtimeWebSocket();

0 commit comments

Comments
 (0)