Add Langfuse traces#423
Conversation
|
work out how to remove API keys from what we send to langfuse. Any other sensitive stuff? |
|
next steps here:
|
|
We're likely to be waiting a while for self-hosting - so let's set up an integration with langfuse cloud which only sends openfn staff chats. That lets us merge and experiment with platform before committing to a self-hosted instance |
|
I will add filtering for employee emails |
c536345 to
43dfe9a
Compare
|
@josephjclark I have added the changes but didn't test it properly yet. So please wait until Monday for this. |
|
I have been testing this and I think it should work ok. Once the front-end adds the requested changes, we can start tracking on Langfuse. |
There was a problem hiding this comment.
So we can safely release this without waiting for Lighting right @hanna-paasivirta ? We just won't get the metrics until lightning sends us the right data
EDIT: Oh actually we get it for global assistant anyways
Yes all new keys are optional, so we can push this without waiting for Lightning to add changes. |
Short Description
Adds Langfuse observability to all three chat services (global_chat, job_chat, workflow_chat) with per-user opt-in control.
Fixes #410
Requested Lightning changes: OpenFn/lightning#4595
We need to figure out self-hosting: #439
Implementation Details
Tracing
Every chat request now produces a structured trace in Langfuse — the full call tree from the top-level
main()through routing, planning, subagent calls, RAG retrieval, and Anthropic API calls. Multi-turn conversations are grouped into Langfuse sessions viasession_id. Anthropic SDK calls are auto-instrumented via OpenTelemetry.Tracking controls
metrics_opt_inboolean in the payload. When absent or false, ashould_export_spanfilter drops all spans before they leave the process — zero data sent to Langfuse.metrics_opt_in(one-line removal when we're ready to rely on the flag).metrics_opt_inthrough subagent payloads.User identity
A new
userobject in the payload carriesid(mapped to Langfuseuser_id) andemployee(added as a Langfuse tag). This lets us filter traces by user and segment employee vs external usage.API key safety
The
@observedecorator onmain()was capturing the entire input dict — includingapi_key— as the trace input. Fixed by addingcapture_input=Falseand explicitly setting only the user's message as the span input.Payload changes (frontend action needed)
Three new optional fields on all services:
{ "user": { "id": "user-abc", "employee": true }, "metrics_opt_in": true, "meta": { "session_id": "..." } }meta.session_idis new and consistent across all three services (global_chat previously usedmetadata— renamed tometafor consistency).AI Usage
Please disclose how you've used AI in this work (it's cool, we just want to know!):
You can read more details in our Responsible AI Policy