Skip to content

fix(client): link dataset run items to observations#841

Merged
marliessophie merged 1 commit into
mainfrom
codex/lfe-10352-js-dataset-link-observation
Jun 16, 2026
Merged

fix(client): link dataset run items to observations#841
marliessophie merged 1 commit into
mainfrom
codex/lfe-10352-js-dataset-link-observation

Conversation

@marliessophie

@marliessophie marliessophie commented Jun 16, 2026

Copy link
Copy Markdown
Member

Summary

  • Send observationId from otelSpan.spanContext().spanId when using manual dataset item .link().
  • Add a targeted e2e assertion that linked generation run items include the observation id.

Linear: LFE-10352

Verification

  • Not run per request.

Greptile Summary

This PR fixes dataset run item linking by also sending the observationId (derived from otelSpan.spanContext().spanId) alongside the existing traceId, enabling the Langfuse server to associate a run item with a specific observation rather than just its parent trace. The pattern is consistent with how score/index.ts already populates observationId for scoring operations.

  • packages/client/src/dataset/index.ts: Destructures spanId alongside traceId from otelSpan.spanContext() and passes it as observationId in the datasetRunItems.create call.
  • tests/e2e/datasets.e2e.test.ts: Adds an assertion that the linked generation run item contains observationId: generation.id, confirming the span ID round-trips correctly (aligned with spanWrapper.ts line 151 where this.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
Loading
%%{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: DatasetRunItem
Loading

Reviews (1): Last reviewed commit: "fix(client): link dataset run items to o..." | Re-trigger Greptile

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
langfuse-js Ready Ready Preview Jun 16, 2026 3:12pm

Request Review

@github-actions

Copy link
Copy Markdown

@claude review

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@marliessophie
marliessophie merged commit 628f21e into main Jun 16, 2026
17 of 19 checks passed
@marliessophie
marliessophie deleted the codex/lfe-10352-js-dataset-link-observation branch June 16, 2026 15:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant