Skip to main content

OpenInference instrumentation for the snowglobe client

Project description

Snowlgobe Telemetry Instrumentation for OpenInference

Instrument your Snowglobe connected app with OpenInference and start sending traces to popular OpenInference compatible sinks like Arize or Arize Phoenix.

Installation

pip install snowglobe-telemetry-openinference

If using uv, set the --prerelease=allow flag

uv pip install --prerelease=allow snowglobe-telemetry-openinference

Add the OpenInferenceInstrumentor to your agent file

Reminder: Each agent wrapper file resides in the root directory of your project, and is named after the agent (e.g. My Agent Name becomes my_agent_name.py).

from snowglobe.client import CompletionRequest, CompletionFunctionOutputs
from openai import OpenAI
import os

### Add these two lines to your agent file and watch context rich traces come in!
from snowglobe.telemetry.openinference import OpenInferenceInstrumentor
OpenInferenceInstrumentor().instrument()


client = OpenAI(api_key=os.getenv("SNOWGLOBE_API_KEY"))

def completion_fn(request: CompletionRequest) -> CompletionFunctionOutputs:
    """
    Process a scenario request from Snowglobe.
    
    This function is called by the Snowglobe client to process requests. It should return a
    CompletionFunctionOutputs object with the response content.

    Example CompletionRequest:
    CompletionRequest(
        messages=[
            SnowglobeMessage(role="user", content="Hello, how are you?", snowglobe_data=None),
        ]
    )

    Example CompletionFunctionOutputs:
    CompletionFunctionOutputs(response="This is a string response from your application")
    
    Args:
        request (CompletionRequest): The request object containing the messages.

    Returns:
        CompletionFunctionOutputs: The response object with the generated content.
    """

    # Process the request using the messages. Example:
    messages = request.to_openai_messages()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages
    )
    return CompletionFunctionOutputs(response=response.choices[0].message.content)

Enhancing Snowglobe Connect SDK's Traces with OpenInference Integrations

You can add more rich context to the traces the Snowglobe Connect SDK captures by installing additional OpenInference instrumentors and registering the appropriate tracer provider in your agent wrapper file.

The below examples shows how to add OpenAI instrumentation for either Arize or Arize Phoenix in addition to Snowglobe's OpenInference instrumentation:

Arize

Install the Arize OpenTelemetry pacakge and the OpenAI specific instrumentor.

pip install openinference-instrumentation-openai arize-otel

Then register the tracer provider and use the OpenAI instrumentator in your agent file:

import os
from openai import OpenAI
from snowglobe.client import CompletionRequest, CompletionFunctionOutputs
from arize.otel import register

# Setup OTel via our convenience function
tracer_provider = register(
    space_id = "your-space-id", # in app space settings page
    api_key = "your-api-key", # in app space settings page
    project_name = "your-project-name", # name this to whatever you would like
)

# Import the OpenAI instrumentor from OpenInference
from openinference.instrumentation.openai import OpenAIInstrumentor

# Instrument OpenAI
OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)

# Import the OpenInference instrumentor from Snowglobe
from snowglobe.telemetry.openinference import OpenInferenceInstrumentor

# Instrument the Snowglobe client
OpenInferenceInstrumentor().instrument(tracer_provider=tracer_provider)


def completion_fn(request: CompletionRequest) -> CompletionFunctionOutputs:
    messages = request.to_openai_messages()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages
    )
    return CompletionFunctionOutputs(response=response.choices[0].message.content)

Arize Phoenix

Install the Arize Phoenix OpenTelemetry pacakge and the OpenAI specific instrumentor.

pip install openinference-instrumentation-openai arize-phoenix-otel

Then register the tracer provider and use the OpenAI instrumentator in your agent file:

import os
from openai import OpenAI
from snowglobe.client import CompletionRequest, CompletionFunctionOutputs
from phoenix.otel import register

os.environ["PHOENIX_COLLECTOR_ENDPOINT"] = "http://localhost:6006"

# configure the Phoenix tracer
tracer_provider = register(
  project_name="my-llm-app", # Default is 'default'
)

# Import the OpenAI instrumentor from OpenInference
from openinference.instrumentation.openai import OpenAIInstrumentor

# Instrument OpenAI
OpenAIInstrumentor().instrument(tracer_provider=tracer_provider)

# Import the OpenInference instrumentor from Snowglobe
from snowglobe.telemetry.openinference import OpenInferenceInstrumentor

# Instrument the Snowglobe client
OpenInferenceInstrumentor().instrument(tracer_provider=tracer_provider)


def completion_fn(request: CompletionRequest) -> CompletionFunctionOutputs:
    messages = request.to_openai_messages()
    response = client.chat.completions.create(
        model="gpt-4o-mini",
        messages=messages
    )
    return CompletionFunctionOutputs(response=response.choices[0].message.content)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

snowglobe_telemetry_openinference-0.0.0a0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file snowglobe_telemetry_openinference-0.0.0a0.tar.gz.

File metadata

File hashes

Hashes for snowglobe_telemetry_openinference-0.0.0a0.tar.gz
Algorithm Hash digest
SHA256 36cdc3414fe128039a3bee9fe3b0750a13476b41a4bb6822e9983f3323bfcb13
MD5 2a45820cab6ec1b041d716022767a545
BLAKE2b-256 2e80a82632c403639a13b507f1fd2261d4a828858bdc365fb1509d4724f60250

See more details on using hashes here.

File details

Details for the file snowglobe_telemetry_openinference-0.0.0a0-py3-none-any.whl.

File metadata

File hashes

Hashes for snowglobe_telemetry_openinference-0.0.0a0-py3-none-any.whl
Algorithm Hash digest
SHA256 22ae5abcaea08b784628c0727495dd27a1f4478a150254cfda7f5df4972858bd
MD5 305018e59e0c26a3c88428d65f16431b
BLAKE2b-256 cec7166907874b12aff0ec652620180781cdebadaf4ff3a1d3c7300252e8c8a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page