Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,16 @@
"method": "delete",
"span_name": "pinecone.delete",
},
{
"object": "PineconeInference",
"method": "embed",
"span_name": "pinecone.inference.embed",
},
{
"object": "PineconeInference",
"method": "rerank",
"span_name": "pinecone.inference.rerank",
},
]


Expand All @@ -75,6 +85,76 @@ def _set_input_attributes(span, instance, kwargs):
set_span_attribute(span, SpanAttributes.SERVER_ADDRESS, instance._config.host)


@dont_throw
def _set_inference_input_attributes(span, kwargs):
"""Set span attributes for Pinecone Inference API calls."""
model = kwargs.get("model")
if model:
set_span_attribute(span, AISpanAttributes.GEN_AI_REQUEST_MODEL, str(model))

# For embed: inputs is a list of texts
inputs = kwargs.get("inputs")
if inputs is not None:
if isinstance(inputs, list):
set_span_attribute(
span, AISpanAttributes.GEN_AI_USAGE_INPUT_COUNT, len(inputs)
)
else:
set_span_attribute(span, AISpanAttributes.GEN_AI_USAGE_INPUT_COUNT, 1)

# For rerank: query and documents
query = kwargs.get("query")
if query:
set_span_attribute(span, AISpanAttributes.GEN_AI_INPUT_CONTENT, str(query))

top_n = kwargs.get("top_n")
if top_n is not None:
set_span_attribute(span, SpanAttributes.PINECONE_RERANK_TOP_N, top_n)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the attribute exists in semconv_ai but not in standard semconv
echo "=== Checking AISpanAttributes for PINECONE_RERANK_TOP_N ==="
rg -n "PINECONE_RERANK_TOP_N" --type py

echo "=== Checking semconv_ai SpanAttributes definition ==="
python -c "from opentelemetry.semconv_ai import SpanAttributes; print([a for a in dir(SpanAttributes) if 'PINECONE' in a])" 2>/dev/null || echo "Could not import semconv_ai"

echo "=== Checking standard semconv SpanAttributes ==="
python -c "from opentelemetry.semconv.trace import SpanAttributes; print([a for a in dir(SpanAttributes) if 'PINECONE' in a])" 2>/dev/null || echo "Could not import semconv.trace"

Repository: traceloop/openllmetry

Length of output: 440


🏁 Script executed:

# Check the imports and the relevant code sections
head -50 packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py | grep -E "^from|^import"

Repository: traceloop/openllmetry

Length of output: 997


🏁 Script executed:

# Read the _set_inference_input_attributes function around line 112
sed -n '88,115p' packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py

Repository: traceloop/openllmetry

Length of output: 1004


🏁 Script executed:

# Check lines 167, 170 mentioned in the review
sed -n '165,175p' packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py

Repository: traceloop/openllmetry

Length of output: 448


Change line 112 to use AISpanAttributes instead of SpanAttributes.

SpanAttributes from opentelemetry.semconv.trace does not contain Pinecone-specific attributes like PINECONE_RERANK_TOP_N. These attributes are defined in AISpanAttributes from opentelemetry.semconv_ai, as correctly used in lines 167-170 for PINECONE_USAGE_READ_UNITS and PINECONE_USAGE_WRITE_UNITS. Accessing SpanAttributes.PINECONE_RERANK_TOP_N will raise an AttributeError at runtime.

Fix
-        set_span_attribute(span, SpanAttributes.PINECONE_RERANK_TOP_N, top_n)
+        set_span_attribute(span, AISpanAttributes.PINECONE_RERANK_TOP_N, top_n)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
set_span_attribute(span, SpanAttributes.PINECONE_RERANK_TOP_N, top_n)
set_span_attribute(span, AISpanAttributes.PINECONE_RERANK_TOP_N, top_n)
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py`
at line 112, The call to set_span_attribute with
SpanAttributes.PINECONE_RERANK_TOP_N on line 112 is using the wrong attributes
class. Replace SpanAttributes with AISpanAttributes in the set_span_attribute
call for PINECONE_RERANK_TOP_N, since Pinecone-specific attributes are defined
in AISpanAttributes from opentelemetry.semconv_ai (as already correctly used in
lines 167-170 for PINECONE_USAGE_READ_UNITS and PINECONE_USAGE_WRITE_UNITS), not
in SpanAttributes from opentelemetry.semconv.trace. This will prevent an
AttributeError at runtime when the span attribute is accessed.



@dont_throw
def _set_inference_response_attributes(span, response):
"""Set span attributes for Pinecone Inference API responses."""
if response is None:
return

# For embed responses
if hasattr(response, "data") and response.data:
set_span_attribute(
span, AISpanAttributes.GEN_AI_USAGE_OUTPUT_COUNT, len(response.data)
)
# Embedding dimensions from first embedding
first_emb = response.data[0]
if hasattr(first_emb, "values") and first_emb.values:
set_span_attribute(
span,
SpanAttributes.PINECONE_EMBEDDING_DIMENSIONALITY,
len(first_emb.values),
)

# For rerank responses
if hasattr(response, "results") and response.results:
set_span_attribute(
span, SpanAttributes.PINECONE_RERANK_RESULT_COUNT, len(response.results)
)
Comment on lines +129 to +139

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Same issue: SpanAttributes does not contain Pinecone-specific attributes.

Lines 131 and 138 use SpanAttributes.PINECONE_EMBEDDING_DIMENSIONALITY and SpanAttributes.PINECONE_RERANK_RESULT_COUNT, but these Pinecone-specific attributes should come from AISpanAttributes.

🐛 Proposed fix
         if hasattr(first_emb, "values") and first_emb.values:
             set_span_attribute(
                 span,
-                SpanAttributes.PINECONE_EMBEDDING_DIMENSIONALITY,
+                AISpanAttributes.PINECONE_EMBEDDING_DIMENSIONALITY,
                 len(first_emb.values),
             )

     # For rerank responses
     if hasattr(response, "results") and response.results:
         set_span_attribute(
-            span, SpanAttributes.PINECONE_RERANK_RESULT_COUNT, len(response.results)
+            span, AISpanAttributes.PINECONE_RERANK_RESULT_COUNT, len(response.results)
         )
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@packages/opentelemetry-instrumentation-pinecone/opentelemetry/instrumentation/pinecone/__init__.py`
around lines 129 - 139, The Pinecone-specific span attributes used in the
set_span_attribute calls are incorrectly sourced from SpanAttributes instead of
AISpanAttributes. Replace SpanAttributes.PINECONE_EMBEDDING_DIMENSIONALITY with
AISpanAttributes.PINECONE_EMBEDDING_DIMENSIONALITY in the first
set_span_attribute call, and replace SpanAttributes.PINECONE_RERANK_RESULT_COUNT
with AISpanAttributes.PINECONE_RERANK_RESULT_COUNT in the second
set_span_attribute call. This ensures Pinecone-specific attributes are correctly
imported and referenced from the appropriate attributes class.


# Usage info
usage = None
if hasattr(response, "usage"):
usage = response.usage
elif isinstance(response, dict) and response.get("usage"):
usage = response["usage"]

if usage:
read_units = getattr(usage, "read_units", None) or (
usage.get("read_units") if isinstance(usage, dict) else None
)
if read_units:
set_span_attribute(
span, AISpanAttributes.PINECONE_USAGE_READ_UNITS, read_units
)


@dont_throw
def _set_response_attributes(
span, read_units_metric, write_units_metric, shared_attributes, response
Expand Down Expand Up @@ -138,19 +218,26 @@ def _wrap(
return wrapped(*args, **kwargs)

name = to_wrap.get("span_name")
is_inference = name is not None and name.startswith("pinecone.inference.")

span_attributes = {}
if not is_inference:
span_attributes[AISpanAttributes.VECTOR_DB_VENDOR] = "Pinecone"

with tracer.start_as_current_span(
name,
kind=SpanKind.CLIENT,
attributes={
AISpanAttributes.VECTOR_DB_VENDOR: "Pinecone",
},
attributes=span_attributes,
record_exception=False,
set_status_on_exception=False,
) as span:
if span.is_recording():
_set_input_attributes(span, instance, kwargs)
if to_wrap.get("method") == "query":
set_query_input_attributes(span, kwargs)
if is_inference:
_set_inference_input_attributes(span, kwargs)
else:
_set_input_attributes(span, instance, kwargs)
if to_wrap.get("method") == "query":
set_query_input_attributes(span, kwargs)

shared_attributes = {}
if hasattr(instance, "_config"):
Expand All @@ -172,16 +259,21 @@ def _wrap(

if response:
if span.is_recording():
if to_wrap.get("method") == "query":
set_query_response(span, scores_metric, shared_attributes, response)

_set_response_attributes(
span,
read_units_metric,
write_units_metric,
shared_attributes,
response,
)
if is_inference:
_set_inference_response_attributes(span, response)
else:
if to_wrap.get("method") == "query":
set_query_response(
span, scores_metric, shared_attributes, response
)

_set_response_attributes(
span,
read_units_metric,
write_units_metric,
shared_attributes,
response,
)

span.set_status(Status(StatusCode.OK))

Expand Down Expand Up @@ -265,40 +357,26 @@ def _instrument(self, **kwargs):
wrapped_method,
),
)
elif wrap_object == "GRPCIndex":
elif wrap_object == "PineconeInference":
# Pinecone Inference API (embed, rerank)
# The inference module is at pinecone.inference
try:
if importlib.util.find_spec("pinecone.db_data.index") is not None:
try:
wrap_function_wrapper(
"pinecone.db_data.index",
f"{wrap_object}.{wrap_method}",
_wrap(
tracer,
query_duration_metric,
read_units_metric,
write_units_metric,
scores_metric,
wrapped_method,
),
)
continue
except (ImportError, AttributeError):
pass
except (ModuleNotFoundError, ImportError):
pass

if getattr(pinecone, wrap_object, None):
wrap_function_wrapper(
"pinecone",
f"{wrap_object}.{wrap_method}",
_wrap(
tracer,
query_duration_metric,
read_units_metric,
write_units_metric,
scores_metric,
wrapped_method,
),
if getattr(pinecone, "inference", None):
wrap_function_wrapper(
"pinecone.inference",
f"{wrap_object}.{wrap_method}",
_wrap(
tracer,
query_duration_metric,
read_units_metric,
write_units_metric,
scores_metric,
wrapped_method,
),
)
except (ModuleNotFoundError, ImportError, AttributeError) as e:
logger.debug(
f"Failed to wrap pinecone.inference.{wrap_object}.{wrap_method}: {e}"
)

def _uninstrument(self, **kwargs):
Expand All @@ -322,6 +400,14 @@ def _uninstrument(self, **kwargs):
f"Failed to unwrap pinecone.db_data.index.GRPCIndex.{wrap_method_name}: {e}"
)

if wrap_object == "PineconeInference":
try:
unwrap(f"pinecone.inference.{wrap_object}", wrap_method_name)
except Exception as e:
logger.debug(
f"Failed to unwrap pinecone.inference.{wrap_object}.{wrap_method_name}: {e}"
)

try:
unwrap(f"pinecone.{wrap_object}", wrap_method_name)
except Exception as e:
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.61.0"
__version__ = "0.62.0"