fix(client): link dataset run items to observations#841
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
@claude review |
There was a problem hiding this comment.
LGTM, small fix to populate observationId on linked dataset run items, with an e2e assertion to match.
Extended reasoning...
Overview
This PR is a two-line behavior fix in packages/client/src/dataset/index.ts: when a dataset item's .link() is called, the implementation now also sends observationId (derived from otelSpan.spanContext().spanId) alongside the existing traceId when creating the dataset run item. The e2e test in tests/e2e/datasets.e2e.test.ts is updated to assert that the linked generation run item includes observationId: generation.id.
Security risks
None. The change passes an additional identifier already retrieved from the same OTel span context to an internal API call. No auth, crypto, permissions, input validation, or untrusted-data paths are touched.
Level of scrutiny
Low. The diff is mechanical, scoped to a single function (createDatasetItemLinkFunction), and aligned with the PR description and Linear ticket (LFE-10352). spanContext().spanId is the standard OTel API and is what's exposed publicly on the observation as .id in this SDK, matching the test assertion generation.id.
Other factors
The change is covered by an updated e2e test that exercises the exact code path. There are no outstanding reviewer comments and no prior reviews from me on this PR. This is a safe shadow-approval candidate.
Summary
observationIdfromotelSpan.spanContext().spanIdwhen using manual dataset item.link().Linear: LFE-10352
Verification
Greptile Summary
This PR fixes dataset run item linking by also sending the
observationId(derived fromotelSpan.spanContext().spanId) alongside the existingtraceId, enabling the Langfuse server to associate a run item with a specific observation rather than just its parent trace. The pattern is consistent with howscore/index.tsalready populatesobservationIdfor scoring operations.packages/client/src/dataset/index.ts: DestructuresspanIdalongsidetraceIdfromotelSpan.spanContext()and passes it asobservationIdin thedatasetRunItems.createcall.tests/e2e/datasets.e2e.test.ts: Adds an assertion that the linked generation run item containsobservationId: generation.id, confirming the span ID round-trips correctly (aligned withspanWrapper.tsline 151 wherethis.id = params.otelSpan.spanContext().spanId).Confidence Score: 5/5
Safe to merge — the change is a minimal, targeted fix to a single function that already handles the trace ID correctly.
The two-line source change follows the exact same pattern already used in score/index.ts for observationId, and the spanId-to-observation.id mapping is confirmed by spanWrapper.ts. The new e2e assertion exercises the changed code path end-to-end. No existing behavior is removed or altered; only the previously missing observationId field is now populated.
No files require special attention.
Sequence Diagram
%%{init: {'theme': 'neutral'}}%% sequenceDiagram participant U as User Code participant LO as LangfuseObservation participant DM as DatasetManager participant API as Langfuse API U->>LO: "startObservation("generation", ..., { asType: "generation" })" Note over LO: this.id = otelSpan.spanContext().spanId U->>DM: "item.link({ otelSpan: generation.otelSpan }, runName)" DM->>DM: "const { traceId, spanId } = otelSpan.spanContext()" DM->>API: "datasetRunItems.create({ traceId, observationId: spanId, ... })" API-->>DM: DatasetRunItem (with observationId linked) DM-->>U: DatasetRunItem%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%% sequenceDiagram participant U as User Code participant LO as LangfuseObservation participant DM as DatasetManager participant API as Langfuse API U->>LO: "startObservation("generation", ..., { asType: "generation" })" Note over LO: this.id = otelSpan.spanContext().spanId U->>DM: "item.link({ otelSpan: generation.otelSpan }, runName)" DM->>DM: "const { traceId, spanId } = otelSpan.spanContext()" DM->>API: "datasetRunItems.create({ traceId, observationId: spanId, ... })" API-->>DM: DatasetRunItem (with observationId linked) DM-->>U: DatasetRunItemReviews (1): Last reviewed commit: "fix(client): link dataset run items to o..." | Re-trigger Greptile