Repository navigation
Conversation
…er and AI clients MCDB-103303 #closes Co-authored-by: Cursor <cursoragent@cursor.com>
There was a problem hiding this comment.
🟢 Approval recommended
The propagation paths, optional-dependency behavior, logging integration, and synchronous/asynchronous clients are implemented consistently and covered by targeted tests.
0 open findings
What changed in this PR
Adds end-to-end W3C trace-context propagation through UDF execution and outbound AI requests.
Changes:
- Extracts incoming trace context and adds trace IDs to UDF logs.
- Adds reusable synchronous/asynchronous HTTP header-injection hooks.
- Extends AI-client tests and test dependencies for OpenTelemetry.
| File | Description |
|---|---|
singlestoredb/utils/otel.py |
Provides reusable OpenTelemetry injection hooks. |
singlestoredb/functions/ext/asgi.py |
Propagates request trace context through UDF execution. |
singlestoredb/functions/ext/utils.py |
Permits trace IDs in JSON logs. |
singlestoredb/ai/chat.py |
Uses shared sync/async tracing hooks. |
singlestoredb/ai/embeddings.py |
Adds tracing to OpenAI, Azure, and Bedrock requests. |
singlestoredb/tests/test_udf_trace_context.py |
Tests UDF propagation and logging. |
singlestoredb/tests/test_embeddings.py |
Tests embeddings-client propagation. |
singlestoredb/tests/test_ai_chat.py |
Tests asynchronous chat-client propagation. |
pyproject.toml |
Adds OpenTelemetry API to test dependencies. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This change carries an incoming W3C trace context (
traceparent) through Python UDF execution and forwards it to supported outbound AI requests. This makes it possible to follow one request across the upstream proxy, the UDF, and the downstream model endpoint using the same trace ID.What changed
traceparentand keeps it active while async or sync UDF code runs.TypeErrorpreviously raised by async chat calls such asainvokeandabatch.singlestoredb/utils/otel.py.If
traceparentis missing or invalid, behavior is unchanged. The existing per-requestrequest_idis also unchanged.This uses only
opentelemetry-api; it does not create spans or require an OpenTelemetry SDK or exporter. Whenopentelemetry-apiis not installed, tracing remains a no-op. The package is included only in the test dependency group.Compatibility note
When OpenAI or Azure embedding callers do not provide an HTTP client, the factory now creates sync and async httpx clients with a 600-second timeout and a 5-second connection timeout, matching the chat factory. These clients use httpx default connection-pool limits rather than the OpenAI SDK defaults.
Test Plan
ainvoke, and chatbatch: all five requests sent the incomingtraceparentunchanged.JIRA Issues
Closes MCDB-103303