Repository navigation
Conversation
graph() caches the built graph per context so repeated runs skip re-evaluating every node's flag. The build also created the graph's track data, run id included, so every run for the same context reported the same runId on its $ld:ai:graph:* events. Each run now copies the cached track data with a fresh runId and passes it to streamRoute, so the node, handoff and graph-level events of one run share one id and the next run gets another. The flag evaluations stay cached.
Contributor
Author
|
bugbot run |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 9470b95. Configure here.
apucacao
added a commit
that referenced
this pull request
Oct 12, 2026
## Summary Spans from the native graph adapters (`toOpenAIAgents`, `toClaudeAgents`, `toLangGraph`, `toVercelAgents`) had nothing tying them to the graph's AI Config, so Monitoring couldn't find them by config key. - The `launchdarkly.graph` span now gets `setLdSpanAttributes`, like every other handler: config key, run id, context keys and the `feature_flag` event. New helper: `makeGraphTrackData`. - Graph and node tracking events now carry the environment id. - Graph-level events (`$ld:ai:graph:invocation_success` and friends) now use the graph key as `configKey`, matching the span and `graph()`. They used the root node's key. - The `graph()` runner's own `launchdarkly.graph` span gets the same identity. - Every adapter now ends its graph span in a `finally`. `toLangGraph` never ended it, and `toOpenAIAgents` / `toClaudeAgents` left it open on setup errors. - `makeGraphTrackData` is marked `@internal`. - A setup error (an agent that was not built, a graph that fails to compile) now fails the run like a run error does: the span records the exception with ERROR status, and `$ld:ai:graph:invocation_failure` fires. Before, the span ended with no status and no failure event. - Each `graph()` run gets its own run id. The built graph is cached per context, so runs with the same context used to share one id on the span and every graph event. This replaces #109. - `toVercelAgents` no longer sends `$ld:ai:graph:path`, matching the other adapters. The path stays on the span. Python twin: launchdarkly/python-ai-sdk#121. ## Testing - Adapter and client tests cover the span attributes, the event and the environment id. The LangGraph span-end tests fail on main. - Staging: [graph run with this branch](https://ld-stg.launchdarkly.com/projects/default/traces?query=launchdarkly.operation.type%3Dgen_ai+launchdarkly.graph.key%3Dtravel-agent-flow&page=1&relativeTime=last_24_hours&env=production&env=staging&env=alexis-o11y-lab&selected-env=alexis-o11y-lab&related_resource=eyJ0eXBlIjoidHJhY2UiLCJpZCI6IjczYzhjYzU0NWIxNDYxNjg0YWVkMzRjNGU3MDg0MWVkIiwidGltZXN0YW1wIjoiMjAyNi0wOS0zMFQyMzoyNDo1OC45N1oiLCJzcGFuSUQiOiJjNTVmZWFiNjljZjliZDgwIn0%3D). 🤖 Generated with [Claude Code](https://claude.com/claude-code) <!-- CURSOR_SUMMARY --> --- > [!NOTE] > **Overview** > Native graph runs and the client's `graph()` runner now tag **`launchdarkly.graph`** spans with the same LaunchDarkly identity as other handlers via **`setLdSpanAttributes`** and a new **`makeGraphTrackData`** helper, so AI Config Monitoring can correlate traces by graph/config key (including **`feature_flag`** span events with environment id). > > **Telemetry behavior changes:** graph-level `$ld:ai:graph:*` events and **`invocation_failure`** use the **graph flag key** as `configKey` (not the root node); **`environmentId`** is added to graph and node track payloads via **`tryGetEnvironmentId`**. **`graph().stream`** mints a **fresh `runId` per invocation** even when the built graph is cached. Setup failures (compile/build) are handled like run errors: span ERROR status, exception recorded, graph-level failure event, and **`span.end()`** once in **`finally`** (fixes missing/double span lifecycle in LangGraph and other adapters). **`toVercelAgents`** stops emitting **`$ld:ai:graph:path`** as a track event (path remains on the span only). > > <sup>Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit e41fe83. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).</sup> <!-- /CURSOR_SUMMARY --> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Running the same
graph()twice with the same context reported both runs under one run id, so separate runs looked like one in the$ld:ai:graph:*events.graph()caches the built graph per context so it doesn't re-evaluate every node's flag on each call. The run id was created in that build, so it was cached too. Each run now gets a fresh id. Every graph event within a run still shares it, and the flag evaluations stay cached.Python twin: launchdarkly/python-ai-sdk#132. Source branch:
fix/graph-run-id-per-run.Testing
graph.test.ts, for bothinvokeandstream: two runs on onegraph()instance and context get different ids, and all graph events in a run (node, handoff, success) share one. It fails on main.Note
Overview
Fixes graph telemetry so each
invoke/streamrun gets its ownrunId. Repeated calls on the samegraph()instance and LD context were sharing one id because the built graph (and its track payload) is cached per context.Each run now clones the cached track data and assigns a fresh
runIdat execution time. That id is passed throughstreamRoute/streamNodeso all$ld:ai:graph:*events in a run—including handoffs—share it, while flag evaluation stays cached.Adds a parameterized test for
invokeandstreamasserting two runs get different ids and events within a run share one id.Reviewed by Cursor Bugbot for commit 9470b95. Bugbot is set up for automated code reviews on this repo. Configure here.