Skip to content

fix(chromadb,pinecone,weaviate,lancedb,milvus): record exceptions on error spans#4006

Open
Koushik-Salammagari wants to merge 2 commits intotraceloop:mainfrom
Koushik-Salammagari:fix/error-spans-vector-db-instrumentations
Open

fix(chromadb,pinecone,weaviate,lancedb,milvus): record exceptions on error spans#4006
Koushik-Salammagari wants to merge 2 commits intotraceloop:mainfrom
Koushik-Salammagari:fix/error-spans-vector-db-instrumentations

Conversation

@Koushik-Salammagari
Copy link
Copy Markdown

@Koushik-Salammagari Koushik-Salammagari commented Apr 16, 2026

Summary

Fixes #412 (partial — vector DB instrumentation packages)

When vector DB calls raise exceptions, spans were left in UNSET status with no error information. This PR adds proper error recording to five vector DB packages:

  • chromadb (wrapper.py): adds Status, StatusCode import + try/except around wrapped(*args, **kwargs)
  • pinecone (__init__.py): adds try/except around the wrapped call inside the with tracer.start_as_current_span() block
  • weaviate (wrapper.py): adds Status, StatusCode import + try/except
  • lancedb (wrapper.py): adds Status, StatusCode import + try/except
  • milvus (wrapper.py): already had a try/except that set ERROR_TYPE attribute — extended it with span.record_exception(e) and span.set_status(SpanStatus(StatusCode.ERROR)) to complete OTel span status (aliased to avoid conflict with pymilvus Status)

This follows the same approach as #3970 (anthropic/groq/mistralai) and companion PR for LLM instrumentations.

Test plan

  • Trigger an error (e.g. wrong collection name, network failure) for each DB
  • Verify the resulting span has status=ERROR with an attached exception event
  • Verify successful calls still produce status=OK (or UNSET where OK was never set)
  • Run existing test suites: npx nx run-many -t test --projects=opentelemetry-instrumentation-chromadb,opentelemetry-instrumentation-pinecone,opentelemetry-instrumentation-weaviate,opentelemetry-instrumentation-lancedb,opentelemetry-instrumentation-milvus

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting for ChromaDB, LanceDB, Milvus, Pinecone, and Weaviate instrumentations: operation failures are now explicitly recorded and marked as errors in traces, ensuring more accurate and reliable observability of failed calls.

…error spans

When vector DB calls raise exceptions, spans were left in UNSET state
with no error information. Add span.record_exception() and
StatusCode.ERROR to all wrapped call sites. Milvus already set
ERROR_TYPE attribute; this completes the OTel span status.

Fixes traceloop#412
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Apr 16, 2026

CLA assistant check
All committers have signed the CLA.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 16, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: 1cd830b0-f2a2-4039-9c9b-2f15a13b2c56

📥 Commits

Reviewing files that changed from the base of the PR and between 69e73ec and 4708843.

📒 Files selected for processing (5)
  • packages/opentelemetry-instrumentation-chromadb/opentelemetry/instrumentation/chromadb/wrapper.py
  • packages/opentelemetry-instrumentation-lancedb/opentelemetry/instrumentation/lancedb/wrapper.py
  • packages/opentelemetry-instrumentation-milvus/opentelemetry/instrumentation/milvus/wrapper.py
  • packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py
  • packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate/wrapper.py
✅ Files skipped from review due to trivial changes (1)
  • packages/opentelemetry-instrumentation-chromadb/opentelemetry/instrumentation/chromadb/wrapper.py
🚧 Files skipped from review as they are similar to previous changes (3)
  • packages/opentelemetry-instrumentation-milvus/opentelemetry/instrumentation/milvus/wrapper.py
  • packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate/wrapper.py
  • packages/opentelemetry-instrumentation-lancedb/opentelemetry/instrumentation/lancedb/wrapper.py

📝 Walkthrough

Walkthrough

Instrumentation wrappers for Chromadb, Lancedb, Milvus, Pinecone, and Weaviate now disable automatic span exception/status handling and explicitly catch exceptions to record them on the active span, set the span status to ERROR, and re-raise the exception.

Changes

Cohort / File(s) Summary
Chromadb wrapper
packages/opentelemetry-instrumentation-chromadb/opentelemetry/instrumentation/chromadb/wrapper.py
Start spans with record_exception=False and set_status_on_exception=False; add try/except to wrapped invocation, call span.record_exception(e) and span.set_status(Status(StatusCode.ERROR)) on exception, then re-raise.
Lancedb wrapper
packages/opentelemetry-instrumentation-lancedb/opentelemetry/instrumentation/lancedb/wrapper.py
Same pattern: disable automatic exception/status, wrap call in try/except, explicitly record exception and set span status to ERROR, then re-raise.
Milvus wrapper
packages/opentelemetry-instrumentation-milvus/opentelemetry/instrumentation/milvus/wrapper.py
Disable automatic exception/status, import Status/StatusCode (or SpanStatus variant), record caught exceptions on span and set status to ERROR in exception handler, then re-raise.
Pinecone wrapper
packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py
Wrap wrapped(*args, **kwargs) in try/except with manual span.record_exception(e) and span.set_status(Status(StatusCode.ERROR)); spans started with automatic exception/status disabled.
Weaviate wrapper
packages/opentelemetry-instrumentation-weaviate/opentelemetry/instrumentation/weaviate/wrapper.py
Start spans with record_exception=False and set_status_on_exception=False, add try/except to record exceptions on span and set status to ERROR before re-raising.

Sequence Diagram(s)

sequenceDiagram
    autonumber
    participant Client as Client
    participant Wrapper as Instrumentation Wrapper
    participant Span as OpenTelemetry Span
    participant Backend as Wrapped Service
    Note over Wrapper,Span: Wrapper starts span with record_exception=False,\nset_status_on_exception=False
    Client->>Wrapper: call instrumented method(args)
    Wrapper->>Span: tracer.start_as_current_span(name, record_exception=False, set_status_on_exception=False)
    Wrapper->>Backend: invoke wrapped(*args, **kwargs)
    alt Backend returns successfully
        Backend-->>Wrapper: result
        Wrapper->>Span: optionally emit events/attributes
        Wrapper-->>Client: return result
    else Backend raises exception
        Backend-->>Wrapper: throws Exception e
        Wrapper->>Span: span.record_exception(e)
        Wrapper->>Span: span.set_status(Status(StatusCode.ERROR))
        Wrapper-->>Client: re-raises Exception e
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰
Exceptions whispered, I hop and hear,
I nudge the span, make errors clear,
I mark the fall and raise it high,
No silent bugs beneath the sky,
Hooray — we log them as they fly! 🥕

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: recording exceptions on error spans across five vector DB instrumentation packages (chromadb, pinecone, weaviate, lancedb, milvus).
Linked Issues check ✅ Passed The PR addresses the coding requirement from issue #412 by implementing exception recording and error span status setting across all five vector DB instrumentation packages as required.
Out of Scope Changes check ✅ Passed All changes are focused on the stated objective: adding exception recording and error status handling to the five vector DB instrumentation wrappers; no unrelated modifications detected.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

… managers

Add record_exception=False and set_status_on_exception=False to all
start_as_current_span calls in chromadb, pinecone, weaviate, lancedb,
and milvus wrappers to avoid double-recording exceptions that are
already captured by the explicit span.record_exception(e) calls.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Bug Report: Errors are not logged

2 participants