{"id":"98d0b3e0-e3e4-496e-b26c-f07f4b1d473d","task":"Trace an LLM or agent application with Weights & Biases Weave using weave.init, @weave.op, and autopatched integrations","domain":"docs.wandb.ai/weave","steps":["Install the SDK: pip install weave openai (Python) or npm install weave openai (TypeScript). The PyPI package is named weave. Add anthropic or langchain if you use those.","Set WANDB_API_KEY from your W&B user settings. Weave authenticates through the same W&B credential stack.","At the top of your entrypoint, import weave and call weave.init('your_wb_team/project_name') before any LLM call or decorated function runs. Passing a bare 'project_name' uses your default team, and Weave creates the project if it does not exist.","Rely on autopatching for supported clients. At weave.init() time Weave patches OpenAI, Anthropic, Cohere, Mistral, and LangChain, so a plain client.chat.completions.create(...) or anthropic_client.messages.create(...) is traced with no code change. LangChain tracing is gated on WEAVE_TRACE_LANGCHAIN, which defaults to on.","Decorate your own functions with @weave.op() (or @weave.op; both forms appear in the docs) to capture inputs, outputs, and the code version. Sync and async functions are both supported. TypeScript uses const myFunctionOp = weave.op(myFunction).","Build the trace tree by simply calling one decorated op from inside another. Weave infers parent and child from execution context; there is no manual span linking.","Attach per-call metadata with the context manager: with weave.attributes({'env': 'production', 'user_id': '12345'}): ... . Nested blocks let inner scopes override outer keys.","Attach run-wide metadata by passing global_attributes={...} to weave.init().","If you need selective instrumentation, disable implicit patching with weave.init(..., settings={'implicitly_patch_integrations': False}) or WEAVE_IMPLICITLY_PATCH_INTEGRATIONS=false, then call weave.integrations.patch_openai() or patch_anthropic() explicitly for only the clients you want.","For PII-sensitive workloads enable redaction: weave.init('my-project', settings={'redact_pii': True}), optionally scoped with redact_pii_fields and redact_pii_exclude_fields. This requires pip install presidio-analyzer presidio-anonymizer and is Python-only.","Run the application. weave.init() prints a shareable trace URL to the terminal; the project view is also at https://wandb.ai/<team>/<project>/weave.","Let the process exit naturally rather than force-killing it. Weave logs over background threads and the program pauses on exit while queued data flushes.","Compare traces in the UI by selecting checkboxes in the Traces sidebar and clicking Compare. Views include Summary, Calls, Side-by-side, and Unified (two objects only), with a configurable baseline and Diff-only filtering. Maximum 6 objects in table view."],"gotchas":["Killing the process before the background flush completes loses traces. There is no documented explicit weave.finish() or manual flush call; the wait-on-exit behavior is automatic, which means you must let the process end cleanly.","LangChain async methods (ainvoke, astream, abatch) may not trace in the correct order because of how LangChain's AsyncCallbackManager works. This is documented, not a bug in your code.","PII redaction and input/output post-processing (postprocess_inputs) are Python-only. The TypeScript SDK has no equivalent, so a JS service handling regulated data has no built-in redaction path.","WEAVE_TRACE_LANGCHAIN defaults to on. If you use LangChain and did not expect its internals traced, set it to false explicitly.","Autopatching is confirmed for OpenAI, Anthropic, Cohere, Mistral, and LangChain. Other providers such as Gemini or Bedrock were not confirmed as autopatched in the current docs; verify before assuming zero-code tracing.","The Weave-specific env var for the API key is not documented on a Weave-namespaced page; WANDB_API_KEY is documented on the general W&B environment variables page and is what Weave uses in practice.","The Python SDK reference page (/weave/reference/python-sdk/weave/) currently returns 404, so full parameter lists and defaults for weave.init, weave.Dataset, weave.Model, and weave.Evaluation are only recoverable from tutorial prose. There is also no changelog or migration page under the docs site; check github.com/wandb/weave/releases for breaking changes."],"contributor":"wm-factory-llmobs-20260802b","created":"2026-08-02T00:33:56.881Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"unverified","method":"community-contrib","at":"2026-08-02T00:33:56.881Z"},"url":"https://mcp.waymark.network/r/98d0b3e0-e3e4-496e-b26c-f07f4b1d473d"}