Integrations
Pinecone

Setup

Step 1: Installing Packages

pip install opentelemetry-instrumentation-pinecone

Step 2: Telemetry Configuration

Configure your application to collect and send telemetry data. Add the following lines to your python file:

import os
 
from opentelemetry import trace
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace import TracerProvider
from opentelemetry.sdk.trace.export import (
    BatchSpanProcessor
)
from opentelemetry.exporter.otlp.proto.grpc.trace_exporter import (
    OTLPSpanExporter
)
 
OTEL_EXPORTER_OTLP_ENDPOINT = "collector.infrastack.ai"
OTEL_EXPORTER_OTLP_HEADERS = "infrastack-api-key=<API-KEY>"
 
os.environ["OTEL_EXPORTER_OTLP_ENDPOINT"] = OTEL_EXPORTER_OTLP_ENDPOINT
os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = OTEL_EXPORTER_OTLP_HEADERS
 
otlp_exporter = OTLPSpanExporter(
    endpoint = OTEL_EXPORTER_OTLP_ENDPOINT,
    headers=(tuple(OTEL_EXPORTER_OTLP_HEADERS.split("=")),)
)
 
processor = BatchSpanProcessor(otlp_exporter)
provider = TracerProvider(resource=Resource.create({"service.name": "pinecone.traces"}))
provider.add_span_processor(processor)

Now, add the intrumentation to the Pinecone API,

import pinecone
 
from opentelemetry.instrumentation.pinecone import PineconeInstrumentor
 
PineconeInstrumentor().instrument(tracer_provider = provider)

Step 3: Using the Pinecone API

All the Pinecone APIs can be used without modification and intrumentation provides immediate traces for this framework, i.e.

from pinecone import Pinecone, ServerlessSpec
 
pc = Pinecone(api_key=<PINECONE-API-KEY>)
 
pc.create_index(
  name="my-index",
  dimension=1536,
  metric="euclidean",
  spec=ServerlessSpec(
      cloud='aws',
      region='us-east-1'
  )
)