Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fuzzy-seas-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@openai/agents-realtime': patch
---

fix: #633 fix a bug where tracingDisabled in realtime config does not work
2 changes: 1 addition & 1 deletion packages/agents-realtime/src/openaiRealtimeBase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -672,7 +672,7 @@ export abstract class OpenAIRealtimeBase
*
* @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
*/
protected _updateTracingConfig(tracingConfig: RealtimeTracingConfig) {
protected _updateTracingConfig(tracingConfig: RealtimeTracingConfig | null) {
if (typeof this.#tracingConfig === 'undefined') {
// treating it as default value
this.#tracingConfig = null;
Expand Down
6 changes: 5 additions & 1 deletion packages/agents-realtime/src/openaiRealtimeWebRtc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,11 @@ export class OpenAIRealtimeWebRTC
if (parsed.type === 'session.created') {
this._tracingConfig = parsed.session.tracing;
// Trying to turn on tracing after the session is created
this._updateTracingConfig(userSessionConfig.tracing ?? 'auto');
const tracingConfig =
typeof userSessionConfig.tracing === 'undefined'
? 'auto'
: userSessionConfig.tracing;
this._updateTracingConfig(tracingConfig);
}
});

Expand Down
6 changes: 5 additions & 1 deletion packages/agents-realtime/src/openaiRealtimeWebsocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,11 @@ export class OpenAIRealtimeWebSocket
} else if (parsed.type === 'session.created') {
this._tracingConfig = parsed.session.tracing;
// Trying to turn on tracing after the session is created
this._updateTracingConfig(sessionConfig.tracing ?? 'auto');
const tracingConfig =
typeof sessionConfig.tracing === 'undefined'
? 'auto'
: sessionConfig.tracing;
this._updateTracingConfig(tracingConfig);
}
});

Expand Down
2 changes: 2 additions & 0 deletions packages/agents-realtime/src/realtimeSession.ts
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ export class RealtimeSession<
this.#context,
);

// Realtime expects tracing to be explicitly null to disable it; leaving the previous config
// in place would otherwise continue emitting spans.
const tracingConfig: RealtimeTracingConfig | null = this.options
.tracingDisabled
? null
Expand Down
31 changes: 31 additions & 0 deletions packages/agents-realtime/test/openaiRealtimeWebsocket.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,37 @@ describe('OpenAIRealtimeWebSocket', () => {
expect(() => ws.mute(true)).toThrow('Mute is not supported');
});

it('disables tracing when initial config sets tracing to null', async () => {
const updateSpy = vi.spyOn(
OpenAIRealtimeBase.prototype as any,
'_updateTracingConfig',
);
const ws = new OpenAIRealtimeWebSocket();
const connectPromise = ws.connect({
apiKey: 'ek',
model: 'm',
initialSessionConfig: {
tracing: null,
},
});
await vi.runAllTimersAsync();
await connectPromise;

lastFakeSocket!.emit('message', {
data: JSON.stringify({
type: 'session.created',
event_id: 'evt_1',
session: {
tracing: 'auto',
},
}),
});

expect(updateSpy).toHaveBeenCalled();
const lastCall = updateSpy.mock.calls.at(-1);
expect(lastCall?.[0]).toBeNull();
});

it('sendAudio only sends when connected', async () => {
const baseSpy = vi.spyOn(OpenAIRealtimeBase.prototype, 'sendAudio');
const ws = new OpenAIRealtimeWebSocket();
Expand Down