-
Notifications
You must be signed in to change notification settings - Fork 76
Fix browser and cloudflare trace exports #50
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
🦋 Changeset detectedLatest commit: 08508ab The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This should fix #16 @threepointone if you want to take a look This should also further fix #10 removing the warning log |
I'll have a look this weekend! thanks so much @dkundel-openai, legend. |
Ok, I think I have a clean solution without mucking about ALS etc. tldr -
diff --git a/integration-tests/cloudflare-workers/worker/src/index.ts b/integration-tests/cloudflare-workers/worker/src/index.ts
index c1d5c72..c132ab8 100644
--- a/integration-tests/cloudflare-workers/worker/src/index.ts
+++ b/integration-tests/cloudflare-workers/worker/src/index.ts
@@ -31,7 +31,6 @@ export default {
try {
setDefaultOpenAIKey(env.OPENAI_API_KEY!);
setTraceProcessors([new BatchTraceProcessor(new ConsoleSpanExporter())]);
- startTraceExportLoop();
const agent = new Agent({
name: 'Test Agent',
@@ -40,13 +39,13 @@ export default {
});
const result = await run(agent, 'Hey there!');
- // make sure you shut down tracing before exiting to flush any remaining traces
- await getGlobalTraceProvider().shutdown();
-
return new Response(`[RESPONSE]${result.finalOutput}[/RESPONSE]`);
} catch (error) {
console.error(error);
return new Response(String(error), { status: 500 });
+ } finally {
+ // make sure to flush any remaining traces before exiting
+ ctx.waitUntil(getGlobalTraceProvider().forceFlush());
}
},
} satisfies ExportedHandler<Env>;
diff --git a/packages/agents-core/src/tracing/provider.ts b/packages/agents-core/src/tracing/provider.ts
index ecbea0a..1b01c0b 100644
--- a/packages/agents-core/src/tracing/provider.ts
+++ b/packages/agents-core/src/tracing/provider.ts
@@ -204,6 +204,10 @@ export class TraceProvider {
});
}
}
+
+ async forceFlush(): Promise<void> {
+ await this.#multiProcessor.forceFlush();
+ }
}
let GLOBAL_TRACE_PROVIDER: TraceProvider | undefined = undefined; |
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
* docs: reset search buttons * docs: fix title link * docs: change line-height of code snippets * docs: color typescript on landing page * docs: change navbar icons to contain text * docs: further design revisions * docs: add github and npm link
* Continue agent execution when function calls are pending * Add tests * Add changeset for tool execution fix 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]> * Fix mock object --------- Co-authored-by: Claude <[email protected]>
* feat(realtime): add changePeerConnection option * feat(realtime): finalize changePeerConnection hook * Update change-peer-connection.md
* feat(openai): pass through unknown hosted tools * Create rich-buses-marry.md
* chore: update version details incl. linking versions * fix build
Co-authored-by: Sunil Pai <[email protected]>
Both Cloudflare and the Browser should not run export loops by default.
This PR:
startTraceExportLoop
and a way toforceFlush
the traces (for Cloudflare)