Skip to content

fix(qdrant): resolve positional args to kwargs in instrumentation wrappers - #1968

Open
todkarsant wants to merge 2 commits into
openlit:mainfrom
todkarsant:fix/qdrant-positional-args
Open

todkarsant wants to merge 2 commits into
openlit:mainfrom
todkarsant:fix/qdrant-positional-args

Conversation

@todkarsant

@todkarsant todkarsant commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #1905

When Qdrant client methods (upsert, query_points, delete, retrieve, scroll, etc.) are called with positional arguments, span attributes like collection_name and data counts are lost because the wrappers only forwarded kwargs to process_qdrant_response.

Changes

  • Use inspect.signature + bind() to resolve positional args into named kwargs before extracting telemetry attributes
  • Applied in both sync (qdrant.py) and async (async_qdrant.py) wrappers
  • All wrapped methods (upsert, query_points, delete, retrieve, scroll, etc.) are covered since the fix is in the shared wrapper path

Before

client.upsert("demo", POINTS) -> span UPSERT unknown, db.vector.count=0

After

client.upsert("demo", POINTS) -> span UPSERT demo, db.vector.count=N

Summary by Sourcery

Bug Fixes:

  • Preserve Qdrant telemetry attributes, including collection names and vector counts, when client methods are invoked with positional arguments in both synchronous and asynchronous instrumentation.

…ppers

When Qdrant client methods (upsert, query_points, delete, retrieve,
scroll, etc.) are called with positional arguments, the instrumentation
wrappers only forwarded kwargs to process_qdrant_response, causing span
attributes like collection_name and data counts to be lost.

Use inspect.signature to bind positional args to their parameter names
before extracting telemetry attributes. Applied to both sync and async
wrappers.

Closes openlit#1905
@todkarsant
todkarsant requested review from a team and ishanjainn as code owners November 19, 2026 13:39
@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Reviewer's Guide

Implementation

Bind positional arguments to parameter names for telemetry extraction in both Qdrant wrappers while preserving the original arguments for the wrapped call.

  • sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py L42-53 (+3 small edits)
  • sdk/python/src/openlit/instrumentation/qdrant/qdrant.py L42-53 (+3 small edits)

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@todkarsant

Copy link
Copy Markdown
Author

@AmanAgarwal041 Could you review this? Fixes Qdrant instrumentation dropping span attributes when methods are called with positional arguments. Thanks!

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

PR Summary by Qodo

Fix positional-argument telemetry in Qdrant wrappers

🐞 Bug fix 🕐 20-40 Minutes

Grey Divider

AI Description

• Resolve positional Qdrant arguments into named values for sync and async telemetry.
• Restore collection names and data counts in spans across wrapped operations.
Merge Risk 🟢 Low

Blast radius 🟢 Low 💥 1 capability

  • 1 affected end-to-end capability after fault-specific containment; implementation boundaries do not widen its functional scope.
  • The sync and async wrappers implement the same bounded end-to-end behavior: observing Qdrant operations and producing OpenTelemetry spans/metrics.
  • They differ by invocation mode but share the same telemetry outcome and response-processing path, so they are one capability rather than independent deployment or technical-layer capabilities.
Sources

sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py[42-52]

        # Bind positional args to their parameter names so that
        # downstream telemetry sees them regardless of how the
        # caller invoked the method.  Keep the original args/kwargs
        # intact for the actual wrapped() call to avoid duplicates.
        try:
            sig = inspect.signature(wrapped)
            bound = sig.bind(*args, **kwargs)
            bound.apply_defaults()
            telemetry_kwargs = bound.arguments
        except (TypeError, ValueError):
            telemetry_kwargs = dict(kwargs)

sdk/python/src/openlit/instrumentation/qdrant/qdrant.py[42-52]

        # Bind positional args to their parameter names so that
        # downstream telemetry sees them regardless of how the
        # caller invoked the method.  Keep the original args/kwargs
        # intact for the actual wrapped() call to avoid duplicates.
        try:
            sig = inspect.signature(wrapped)
            bound = sig.bind(*args, **kwargs)
            bound.apply_defaults()
            telemetry_kwargs = bound.arguments
        except (TypeError, ValueError):
            telemetry_kwargs = dict(kwargs)
Behavioral complexity 🟡 Medium 🧩 Compatibility cases

  • Before: telemetry primarily read collection_name and operation parameters from kwargs, so positional invocation was not represented consistently.
  • After: the wrappers inspect the callable signature, bind positional and keyword arguments, apply defaults, and pass the resulting named mapping to telemetry processing while preserving the original invocation.
  • New correctness condition: every supported sync and async Qdrant invocation form must map to the correct parameter names and defaults without changing the actual wrapped call; binding failures must retain the prior fallback behavior.
  • This is a bounded invocation-compatibility case, not a new concurrency, persistence, or algorithmic invariant.
Sources

sdk/python/src/openlit/instrumentation/qdrant/qdrant.py[42-52]

        # Bind positional args to their parameter names so that
        # downstream telemetry sees them regardless of how the
        # caller invoked the method.  Keep the original args/kwargs
        # intact for the actual wrapped() call to avoid duplicates.
        try:
            sig = inspect.signature(wrapped)
            bound = sig.bind(*args, **kwargs)
            bound.apply_defaults()
            telemetry_kwargs = bound.arguments
        except (TypeError, ValueError):
            telemetry_kwargs = dict(kwargs)

sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py[42-52]

        # Bind positional args to their parameter names so that
        # downstream telemetry sees them regardless of how the
        # caller invoked the method.  Keep the original args/kwargs
        # intact for the actual wrapped() call to avoid duplicates.
        try:
            sig = inspect.signature(wrapped)
            bound = sig.bind(*args, **kwargs)
            bound.apply_defaults()
            telemetry_kwargs = bound.arguments
        except (TypeError, ValueError):
            telemetry_kwargs = dict(kwargs)
Potential damage 🟢 Low 🩹 Reversible

  • The affected capability is observability, not the Qdrant data operation itself.
  • A fault can produce an incorrectly named or incomplete span/metric, reducing monitoring usefulness until code is corrected.
  • Reverting or redeploying the wrapper fixes future telemetry, but already emitted telemetry is not rewritten.
  • Qdrant operation results and stored data remain intact because the original call arguments are preserved and telemetry-processing exceptions return the original response.
  • Revert or redeploy the instrumentation code for future calls.
  • Existing incorrect telemetry may remain in the telemetry backend and may require retention expiry or manual interpretation; no Qdrant data repair or external compensation is indicated.
Sources

sdk/python/src/openlit/instrumentation/qdrant/qdrant.py[42-52]

        # Bind positional args to their parameter names so that
        # downstream telemetry sees them regardless of how the
        # caller invoked the method.  Keep the original args/kwargs
        # intact for the actual wrapped() call to avoid duplicates.
        try:
            sig = inspect.signature(wrapped)
            bound = sig.bind(*args, **kwargs)
            bound.apply_defaults()
            telemetry_kwargs = bound.arguments
        except (TypeError, ValueError):
            telemetry_kwargs = dict(kwargs)

sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py[42-52]

        # Bind positional args to their parameter names so that
        # downstream telemetry sees them regardless of how the
        # caller invoked the method.  Keep the original args/kwargs
        # intact for the actual wrapped() call to avoid duplicates.
        try:
            sig = inspect.signature(wrapped)
            bound = sig.bind(*args, **kwargs)
            bound.apply_defaults()
            telemetry_kwargs = bound.arguments
        except (TypeError, ValueError):
            telemetry_kwargs = dict(kwargs)
Assessed commit f7b37c2
Diagram

graph TD
  S["Sync wrapper"] --> B["Signature binding"] --> N["Span name"] --> Q["Qdrant method"] --> P["Response telemetry"]
  A["Async wrapper"] --> B
  B --> P
Loading
High-Level Assessment

The following are alternative approaches to this PR:

1. Keep invocation and telemetry arguments separate
  • ➕ Preserves the caller's original args and kwargs when invoking Qdrant.
  • ➕ Still supplies resolved argument names to span naming and response telemetry.
  • ➖ Requires a separate telemetry mapping in each wrapper or a shared helper.

Recommendation: Use signature binding for telemetry, but do not replace the kwargs used to invoke the wrapped method. As written, a positional call can pass the same parameter through both args and bound kwargs, raising TypeError before the intended telemetry fix takes effect. Add sync and async positional-call tests for this behavior.

Files changed (2) +24 / -0

Bug fix (2) +24 / -0
async_qdrant.pyBind positional arguments in the async Qdrant wrapper +12/-0

Bind positional arguments in the async Qdrant wrapper

• Uses the wrapped method's signature to map positional arguments and defaults to names before span naming and response processing. The bound mapping also replaces kwargs passed to the wrapped async method.

sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py

qdrant.pyBind positional arguments in the sync Qdrant wrapper +12/-0

Bind positional arguments in the sync Qdrant wrapper

• Applies the same signature binding to synchronous operations so telemetry can read named collection and data arguments. The bound mapping also replaces kwargs passed to the wrapped method.

sdk/python/src/openlit/instrumentation/qdrant/qdrant.py

@qodo-free-for-open-source-projects

qodo-free-for-open-source-projects Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (0) 📘 Rule violations (0) 📎 Requirement gaps (0) 🎨 UX issues (0) 🔗 Cross-repo conflicts (0) 📜 Skill insights (0)

Grey Divider


Action required

1. Positional Qdrant calls now crash ✓ Resolved

Resolving commit: f7b37c2

Resolution reason
The commit stops overwriting kwargs: bound arguments are stored in a separate telemetry_kwargs
variable (with dict(kwargs) fallback on bind failure), and the actual wrapped(*args, **kwargs) call
keeps the original args/kwargs intact. Telemetry uses telemetry_kwargs for collection_name and
attribute extraction. Applied identically to the sync and async wrappers. This avoids the
duplicate-argument TypeError, though it does not add tests or restructure into a flattened mapping
as the suggested fix describes.
Description
Both Qdrant wrappers replace kwargs with bound.arguments, which includes positionally supplied
parameters such as collection_name and points, but retain args when calling `wrapped(*args,
**kwargs). When a caller uses positional arguments such as client.upsert("demo", POINTS)`, the
duplicate values raise TypeError outside the sync wrapper’s try block before Qdrant or response
processing runs; the async call fails the same way, while keyword-only calls continue to work.


Remediation recommended

2. Qdrant telemetry misses variadic kwargs ✓ Resolved

Resolving commit: f7b37c2

Resolution reason
The commit stops overwriting kwargs with bound.arguments: it stores the bound mapping in a separate
telemetry_kwargs variable, falls back to dict(kwargs) on binding failure, and keeps the original
args/kwargs for the actual wrapped() call (in both sync and async wrappers). This removes the
duplicate/altered keywords sent to the client. However, it does not flatten VAR_KEYWORD entries into
the top level for telemetry, so the nested-kwargs lookup miss persists for telemetry_kwargs.get(...)
and the **telemetry_kwargs forwarding to telemetry; the fix is partial and differs from the
suggested flattening approach.
Description
bound.arguments keeps values captured by **kwargs in a nested dict under the parameter name,
while apply_defaults() can add that entry even when no extra options were supplied. When binding
succeeds in either wrapper, top-level telemetry lookups miss passthrough options, and forwarding the
bound mapping passes a kwargs entry instead of the caller’s individual options.

Grey Divider

Tip of the day
💡 Did you know, you can describe a rule in plain language on the Rules page and Qodo drafts it for you

More tips ↗ | Customize Qodo ↗ | Qodo docs ↗

Grey Divider

Qodo Logo

@sourcery-ai

sourcery-ai Bot commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Checked at commit f7b37c2

#1905 Bug: Qdrant instrumentation drops span attributes for positionally-passed arguments · 1 of 1 met

# Requirement Status Notes
1 Positional calls to upsert, query_points, delete, retrieve, and scroll preserve collection names and data attributes, producing the same span attributes as keyword calls. ✅ Met Both shared wrappers bind positional arguments to parameter names before passing telemetry arguments to response processing.

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="sdk/python/src/openlit/instrumentation/qdrant/qdrant.py" line_range="47-49" />
<code_context>
+        # how the caller invoked the method.
+        try:
+            sig = inspect.signature(wrapped)
+            bound = sig.bind(*args, **kwargs)
+            bound.apply_defaults()
+            kwargs = bound.arguments
+        except (TypeError, ValueError):
+            pass
</code_context>
<issue_to_address>
**Positional Qdrant calls fail**

When a sync or async wrapped Qdrant method receives positional arguments, `kwargs = bound.arguments` puts those arguments in `kwargs` while leaving them in `args`, so `wrapped(*args, **kwargs)` passes them twice and raises `TypeError` before the Qdrant operation runs; callers see the operation fail.

Keep the original `args` and `kwargs` for invoking `wrapped`, and use the bound arguments separately for telemetry in both wrappers.

Also at `sdk/python/src/openlit/instrumentation/qdrant/async_qdrant.py:47-49`.
</issue_to_address>

Sourcery assessment

Approval pending. 1 finding to address first.

Blocking findings: sdk/python/src/openlit/instrumentation/qdrant/qdrant.py:49


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

bound.arguments was assigned back to kwargs, but the original args were
still passed to wrapped(*args, **kwargs), causing TypeError from
duplicate arguments. Now bound.arguments is stored in telemetry_kwargs
used only for span attributes, while original args/kwargs go to wrapped().
@todkarsant

Copy link
Copy Markdown
Author

Addressed the Sourcery finding in f7b37c2:

The previous code assigned kwargs = bound.arguments which then got double-passed alongside the original args to wrapped(*args, **kwargs), causing TypeError.

Fixed by storing bound arguments in a separate telemetry_kwargs variable used only for span attribute extraction (collection_name, etc.) and process_qdrant_response(). The original args/kwargs are passed untouched to wrapped(). Applied to both sync and async wrappers.

This branch was previously deployed

1 inactive (outdated) deployment
release-notes — d82c6ce6 Deployed Nov 19, 2026 by todkarsant via Normalize / Conventional title #857
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Qdrant instrumentation drops span attributes for positionally-passed arguments

1 participant