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.7.tar.gz (4.1 kB view details)

Uploaded Source

Built Distribution

traceai_instructor-0.1.7-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: traceai_instructor-0.1.7.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.7.tar.gz
Algorithm Hash digest
SHA256 1cf45ea7f618e5740d939eb1f766a87f2418559516c06cb62e64c865b05aec52
MD5 90715c6fa7a984eb38831952eb1100bd
BLAKE2b-256 7867727ccb60aa5c522faa7b8050b1e7c21cd91a3c9591ceff5b68f84aef194c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: traceai_instructor-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 74355fe27e90658c67b806ab4fb02b173bb5d1b4fd98d2296fdcee0f96efa2f8
MD5 a4ca366e15edbf81b829969fe7d2dc88
BLAKE2b-256 0eda67535ab94a0b1d0db47f57577ab814074ae27f6721fd0455ed14d983189f

See more details on using hashes here.

Supported by

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