traceloop / traceloop/openllmetry

🚀 Feature: More Declarative Instrumentation Wrappers

Open
#538 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
Dominant language
Python
Stars
7.4k
Forks
1.1k
Avg merge
8d 14h
Merged PRs (30d)
2

Description

Which component is this feature for?

All Packages

🔖 Feature description

We should improve our instrumentation wrappers to reduce the required amount of boilerplate per project.

The end-goal is to drive the instrumentations towards a more declarative approach, as much as possible. There will always be exceptions, so the solution also needs to be flexible with this.

🎤 Why is this feature needed ?

Less maintenance overhead.

✌️ How do you aim to achieve this?

We'll need to write some custom tooling for this.

In the weaviate instrumentation PR, I wrote some simple classes to reduce boilerplate, for instance:

class _BatchInstrumentor(_Instrumentor):
    namespace = "db.weaviate.batch"
    mapped_attributes = {
        "add_data_object": [
            "data_object",
            "class_name",
            "uuid",
            "vector",
            "tenant",
        ],
        "flush": [],
    }

We could try and take this further. Python offers an amazing introspection module in the standard library (inspect), so in theory just by passing the function name we should be able to automatically extract all arguments. That should be the default way to instrument methods.

Using such resources, we can then simply map in a declarative way most of the standard objects / functions, like we already do:

WRAPPED_METHODS = [
    {
        "package": chromadb.api.segment,
        "object": "SegmentAPI",
        "method": "_query",
        "span_name": "chroma.query.segment._query"
    },
    {
        "package": chromadb,
        "object": "Collection",
        "method": "add",
        "span_name": "chroma.add"
    },

But without the need to explicitly add calls to set span attributes, as our instrumentation tooling should automatically take care of that:

def _set_add_attributes(span, kwargs):
    _set_span_attribute(span, "db.chroma.add.ids_count", count_or_none(kwargs.get("ids")))
    _set_span_attribute(span, "db.chroma.add.embeddings_count", count_or_none(kwargs.get("embeddings")))
    _set_span_attribute(span, "db.chroma.add.metadatas_count", count_or_none(kwargs.get("metadatas")))
    _set_span_attribute(span, "db.chroma.add.documents_count", count_or_none(kwargs.get("documents")))
🔄️ Additional Information

No response

👀 Have you spent some time to check if this feature request has been raised before?
  • I checked and didn't find similar issue
Are you willing to submit PR?

Yes I am willing to submit a PR!

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the existing _Instrumentor and _BatchInstrumentor examples from the Weaviate instrumentation PR, the WRAPPED_METHODS declarations, and Python's inspect module. Define how declarative wrappers should extract arguments, set attributes, and allow flexible exceptions. Done means instrumentation boilerplate is reduced across the cited examples without removing needed custom behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
observability
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.