Skip to content

otelMiddleware: media generation spans never capture prompt, input media or output, even with captureContent #1526

Closed

Description

@tombeckenham

Summary

otelMiddleware opens one CLIENT span for each media activity call (generateImage, generateVideo, generateAudio, generateSpeech, generateTranscription, …), added via #720. That span carries the provider, the model, the operation name and usage. It never records what was asked for or what came back, even with captureContent: true:

  • no prompt
  • no input media: reference images, start and end frames, source audio for transcription
  • no output: generated image, video or audio URLs, or the transcript text

In PostHog, Langfuse or Datadog every media generation therefore shows up as an empty Input/Output pair with a cost attached. For image-to-video or reference-to-video, where the result depends mostly on the input images, there is nothing in the trace to debug from.

Root cause

startMediaSpan / endMediaSpan (packages/ai/src/middlewares/otel.ts:343–384) only set gen_ai.system, gen_ai.operation.name, gen_ai.request.model and usage. captureContent is only checked on the chat paths.

The inputs are already on the context: GenerationMiddlewareContext.artifactInputs holds the activity inputs. The media path never reads it, and the result is never inspected in the terminal hook.

The only workaround is attributeEnricher / onSpanEnd in every app, reimplementing the per-activity input and output shapes that the library already knows.

Proposal

When captureContent is on, the media span writes the same attributes the chat iteration spans do:

Related

Version

@tanstack/ai 0.58.0 (current main has the same code).

I'm happy to open a PR.

Activity

  1. added a commit that references this issue on Sep 26, 2026
    7ccebaa
  2. added
    waiting-on: maintainer
    on Sep 27, 2026
  3. added a commit that references this issue on Sep 27, 2026
    196371e
  4. added a commit that references this issue on Sep 27, 2026
    f44b6b2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

waiting-on: maintainer

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions