Fix instrumented embedding spans missing the `embeddings` attribute when `include_content=True`

Merged
PY
1mo ago
+20-1

This pull request was posted by Claude Code using claude-opus-5-5 on behalf of David.

Closes #8293

Why we make these changes

With include_content=True, the default, InstrumentedEmbeddingModel.embed wrote the returned vectors into the attributes dict that span creation had already consumed. As a result, the exported span never carried the embeddings attribute that its own logfire.json_schema declares. The fix writes the vectors through attributes_to_set, which reaches the live span via span.set_attributes(), the same path every other response attribute takes.

This PR includes the two-sided regression test from #8364 by @anupamking01, who is credited as co-author on that commit.

New public surface

None.

User-visible behavior

embedder = Embedder(TestEmbeddingModel(dimensions=3), instrument=True)
await embedder.embed_query('hello')
# exported span attributes['embeddings']
# before: missing
# after:  '[[1.0, 1.0, 1.0]]'

Verification

What changes for existing users

Embedding spans recorded with include_content on now carry the embeddings attribute; spans recorded with include_content=False and error spans are unchanged.

PR decisions

2026-11-03 · adopted PR #8295 at 2026-11-03 · iter -

2026-11-03 · carry the fix on #8295 · iter -

2026-11-03 · adoption plan · iter -

2026-11-03 · fold #8364 test as one parametrized capfire test · iter -

  • Decision: Replace pydanty's raw-OTel True-side test with test_instrumentation_embeddings_honor_include_content, parametrized over include_content, carrying #8364's two assertions; drop the opentelemetry-sdk try_import it needed.
  • Why: Mirrors adjacent test_instrumentation_exception_honors_include_content; capfire is the file's idiom and needs no extra import guard. False case overlaps test_limited_instrumentation's full-attribute snapshot.
  • Source: https://github.com/pydantic/pydantic-ai/pull/8364/files
  • Session: ad3e0f6d-83ae-4433-8b87-e96ec5e08bbb

2026-11-04 · pre-push review 1 of 3 at 954ad0f64 · iter -

2026-11-04 · pre-push review 1 of 3 at 954ad0f64 · iter -

2026-11-04 · no second opinion; enqueued at 954ad0f64 · iter -

Checklist

  • No breaking changes in accordance with the version policy.
  • Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it. (N/A: no compatibility impact.)
  • PR title is fit for the release changelog.