Diagnostics: OpenTelemetry span cosmos.embedding_generation
Parent: 46729
Depends on: 46732
Goal
Surface embedding-generation latency, count, and generator type as a first-class telemetry item, so customers and support can see the new step in distributed traces.
Scope
- Inside
_resolve_embeddings (and async sibling), wrap the call to generator.generate_embeddings(...) in:
from azure.core.settings import settings
tracer = settings.tracing_implementation()
if tracer is not None:
with tracer.span(name="cosmos.embedding_generation") as span:
span.add_attribute("cosmos.embedding.count", len(texts))
span.add_attribute("cosmos.embedding.generator_type", type(generator).__name__)
start = time.perf_counter()
vectors = generator.generate_embeddings(list(texts))
span.add_attribute("cosmos.embedding.latency_ms",
int((time.perf_counter() - start) * 1000))
else:
start = time.perf_counter()
vectors = generator.generate_embeddings(list(texts))
_logger.info(
"embedding_generation count=%d generator_type=%s latency_ms=%d",
len(texts), type(generator).__name__,
int((time.perf_counter() - start) * 1000),
)
- Mirror in async aggregator (await the call inside the span).
- Privacy:
- Never log raw input strings.
- Never log returned vectors.
- It is OK to log the parameter key names (e.g.
@documentdb-hybridsearchquery-embedding-0) — they are not customer data.
- If a tracer is configured, also record an event on the span when an exception is raised by the generator (so failures show up in traces, not just logs).
Non-goals
- Do NOT introduce a new logger — reuse the package logger (
logging.getLogger("azure.cosmos")).
- Do NOT add new public diagnostics types (no Python equivalent of .NET's
EmbeddingGenerationDatum).
Files touched
sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/hybrid_search_aggregator.py
sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/hybrid_search_aggregator.py
Acceptance
- With an OpenTelemetry tracer configured, a query that triggers embedding generation produces a child span named
cosmos.embedding_generation with the three documented attributes.
- Without a tracer configured, an
INFO-level log line is produced.
- Tests assert raw text / vectors do not appear in span attributes or log output.
Diagnostics: OpenTelemetry span
cosmos.embedding_generationParent: 46729
Depends on: 46732
Goal
Surface embedding-generation latency, count, and generator type as a first-class telemetry item, so customers and support can see the new step in distributed traces.
Scope
_resolve_embeddings(and async sibling), wrap the call togenerator.generate_embeddings(...)in:@documentdb-hybridsearchquery-embedding-0) — they are not customer data.Non-goals
logging.getLogger("azure.cosmos")).EmbeddingGenerationDatum).Files touched
sdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/hybrid_search_aggregator.pysdk/cosmos/azure-cosmos/azure/cosmos/_execution_context/aio/hybrid_search_aggregator.pyAcceptance
cosmos.embedding_generationwith the three documented attributes.INFO-level log line is produced.