Skip to main content

OpenTelemetry instrumentation for Instructor

Project description

Instructor OpenTelemetry Integration

Overview

This integration provides support for using OpenTelemetry with the Instructor framework. It enables tracing and monitoring of applications built with Instructor.

Installation

  1. Install traceAI Instructor
pip install traceAI-instructor

Set Environment Variables

Set up your environment variables to authenticate with FutureAGI

import os

os.environ["FI_API_KEY"] = FI_API_KEY
os.environ["FI_SECRET_KEY"] = FI_SECRET_KEY

Quickstart

Register Tracer Provider

Set up the trace provider to establish the observability pipeline. The trace provider:

from fi_instrumentation import register
from fi_instrumentation.fi_types import ProjectType

trace_provider = register(
    project_type=ProjectType.OBSERVE,
    project_name="instructor_app"
)

Configure Instructor Instrumentation

Instrument the Instructor client to enable telemetry collection. This step ensures that all interactions with the Instructor SDK are tracked and monitored.

from traceai_instructor import InstructorInstrumentor

InstructorInstrumentor().instrument(tracer_provider=trace_provider)

Create Instructor Components

Set up your Instructor client with built-in observability.

import instructor
from openai import OpenAI
from pydantic import BaseModel

# Define the output structure
class UserInfo(BaseModel):
    name: str
    age: int

# Patch the OpenAI client
client = instructor.patch(client=OpenAI())

user_info = client.chat.completions.create(
    model="gpt-3.5-turbo",
    response_model=UserInfo,
    messages=[
        {
            "role": "system",
            "content": "Extract the name and age from the text and return them in a structured format.",
        },
        {"role": "user", "content": "John Doe is nine years old."},
    ],
)

print(user_info, type(user_info))

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

traceai_instructor-0.1.8.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

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

traceai_instructor-0.1.8-py3-none-any.whl (5.2 kB view details)

Uploaded Python 3

File details

Details for the file traceai_instructor-0.1.8.tar.gz.

File metadata

  • Download URL: traceai_instructor-0.1.8.tar.gz
  • Upload date:
  • Size: 4.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.0.0 CPython/3.13.0 Darwin/24.1.0

File hashes

Hashes for traceai_instructor-0.1.8.tar.gz
Algorithm Hash digest
SHA256 3414835045ca2b6282170a88d391088bf712c6074cad69bb123118aa652262be
MD5 3bc12d204ead6cc312fed3f1637d5e79
BLAKE2b-256 5cbbfb2c073d0964f05a169577ded56a4b78a2916465dcc2df9eacde63e9df45

See more details on using hashes here.

File details

Details for the file traceai_instructor-0.1.8-py3-none-any.whl.

File metadata

File hashes

Hashes for traceai_instructor-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 9500d9ebe9ef895fcc42d740149031f233f9d1506760555409e926626aa4daa3
MD5 0f00c8a0c439d69d5f5cd8ab84ec9978
BLAKE2b-256 53e78b2771db587604a1a218f930ce073dc0c0eef8baaafef6048ac44adc79a5

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