feat: Add W&B Weave Tracing Integration
Summary
This PR adds W&B Weave as a new tracing provider in Dify, resolving the feature request in #14463. The integration follows similar patterns to the existing tracers, allowing users to track LLM calls, workflows, and tool usage in W&B Weave.
Motivation and Context
Many Dify users leverage Weights & Biases for their ML workflow tracking and would benefit from native W&B Weave integration. This addition gives users more flexibility in choosing tracing providers that align with their existing MLOps stack.
Weave offers specialized capabilities for LLM applications:
- Detailed call tracing with input/output capture
- Support for complex application flows
- Rich visualization and analytics
- Integration with evaluation frameworks
Implementation Details
The implementation:
- Adds
Weaveas a new tracing provider option - Creates a
WeaveConfigmodel for storing API key, entity, project, and endpoint configuration - Implements a client wrapper for W&B Weave client
- Develops a tracer class implementing the
BaseTraceInstanceinterface - Integrates with Dify's existing trace queue management system
Dependencies
- Added dependency:
weavepackage for Python SDK integration
The implementation follows Dify's existing patterns to ensure consistency while providing the new functionality needed for W&B Weave integration.
Resolves #14463
Checklist
-
[x] This change requires a documentation update, included: Dify Document :Docs PR
-
[x] I understand that this PR may be closed in case there was no previous discussion or issues. (This doesn't apply to typos!)
-
[x] I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
-
[x] I've updated the documentation accordingly.
-
[x] I ran
dev/reformat(backend) andcd web && npx lint-staged(frontend) to appease the lint gods
@parambharat hi! Friendly reminder that you'd need to resolve the merge conflicts before we get this PR out!
@guchenhe : Apologies, I was on vacation for the last two weeks. I've addressed @aiswaryasankarwork's comments and also resolved the conflicts and pushed the changes.
Hi @aiswaryasankarwork . Pinging again to check if you got a chance to review this PR. Let me know if you need any changes if necessary.
Hi @guchenhe and @aiswaryasankarwork just a gentle reminder to take a look at this PR when you get a chance. It’s been open for a while. Would really appreciate your review. Thanks!
Hi @guchenhe and @aiswaryasankarwork just a gentle reminder to take a look at this PR when you get a chance. It’s been open for a while. Would really appreciate your review. Thanks!
Hi @parambharat thanks alot for the PR! mind adding a few type annotations so it passes mypy typechecking in our CI?
thanks @parambharat again for the fix - I went and tested it out a little, and it seems that when I tried to configure weave as the tracing provider on the popup:
I don't get a response on the frontend, but instead was prompted on the backend command line to login:
2025-04-21 23:21:15,969 INFO [_internal.py:97] 127.0.0.1 - - [21/Apr/2025 23:21:15] "OPTIONS /console/api/apps/3c302975-bf4a-4926-a225-10f84a739d2d/trace-config HTTP/1.1" 200 - Please login to Weights & Biases (https://wandb.ai/) to continue: wandb: Logging into wandb.ai. (Learn how to deploy a W&B server locally: https://wandb.me/wandb-server) wandb: You can find your API key in your browser here: https://wandb.ai/authorize?ref=weave wandb: Paste an API key from your profile and hit enter, or press ctrl+c to quit:
In many scenarios, user who are making apps and configuring tracing may not have access to the backend console. since they would already enter their API key in the popup window, I wonder if you could kindly make the configuration process entirely through Dify's frontend instead :)
Additionally, I am not able to see traces logged to weave after configuring the tracing connection. My setup is in the screenshot and I configured a weave project named dify-tracing-test:
not sure if I did anything wrong and would appreciate if you could take a look.
Thanks so much and excited to get this out the door soon! 🫡
hey @guchenhe, This was unexpected. However, I was able to pinpoint the issue and push a fix. Please take a look and let me know if the issue persists.
hi @parambharat , can confirm the login issue has been fixed! Upon testing, I found that a call to a Dify chatflow app produces 2 traces in weave - for example, an invocation like so:
shows up as a workflow trace and a message trace in weave:
Just wanted to double check whether this is expected behavior before we merge?
Attaching the full weave output fyi: weave_export_dify-weave-integration-test-2_2025-04-26 (1).csv
Hi @guchenhe , yes that's the expected behaviour. Two traces are expected since they are created at different time periods apart. However, they can be grouped by session/trace_id.
merged - thank you @parambharat!