fix(embeddings): export vectors on instrumented spans

Draft
AN
1mo ago
+44-1

Summary

Fixes #8293.

InstrumentedEmbeddingModel currently adds embeddings to the original attributes dict after the OpenTelemetry span has already been created. OpenTelemetry does not observe that later dict mutation, so include_content=True exports the input content and schema but silently omits the embedding vectors.

This draft moves the vector payload into attributes_to_set, which is applied through span.set_attributes(), and adds focused regression coverage for both sides of the include_content gate:

  • include_content=True exports the exact result embeddings
  • include_content=False continues to omit them

TDD / verification so far

I reproduced the underlying OpenTelemetry behavior independently:

  • mutating the attributes dict after start_as_current_span(...) does not add the new attribute to the exported span
  • calling span.set_attributes(...) does add it

The production change is intentionally one line and follows the existing late-response attribute path in the same function.

Draft status

This is intentionally a draft. The existing provider inline snapshots in tests/test_embeddings.py also need to be refreshed to include the newly exported embeddings attribute for the include_content=True OpenAI, Bedrock, and Gemini instrumentation cases. I have not marked this ready for review until those expected snapshot changes are included and the relevant repository test target can be run.

I am keeping the include_content=False snapshots unchanged.

Scope

No API or schema shape change beyond making the already-declared embeddings span attribute actually appear when content capture is enabled.