Skip to main content

OpenTelemetry instrumentation for Langchain

Project description

LangChain OpenTelemetry Integration

Overview

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

Installation

  1. Install traceAI LangChain
pip install traceAI-langchain
  1. Install LangChain OpenAI
pip install langchain-openai

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
os.environ["OPENAI_API_KEY"] = OPENAI_API_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="langchain_app",
    session_name="chat-bot"
)

Configure LangChain Instrumentation

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

from traceai_langchain import LangChainInstrumentor

LangChainInstrumentor().instrument(tracer_provider=trace_provider)

Create LangChain Components

Set up your LangChain client with built-in observability.

from langchain_openai import ChatOpenAI
from langchain_core.prompts import ChatPromptTemplate

prompt = ChatPromptTemplate.from_template("{x} {y} {z}?").partial(x="why is", z="blue")
chain = prompt | ChatOpenAI(model_name="gpt-3.5-turbo")

def run_chain():
    try:
        result = chain.invoke({"y": "sky"})
        print(f"Response: {result}")
    except Exception as e:
        print(f"Error executing chain: {e}")

if __name__ == "__main__":
    run_chain()

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

Uploaded Source

Built Distribution

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

traceai_langchain-0.1.10-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file traceai_langchain-0.1.10.tar.gz.

File metadata

  • Download URL: traceai_langchain-0.1.10.tar.gz
  • Upload date:
  • Size: 13.3 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_langchain-0.1.10.tar.gz
Algorithm Hash digest
SHA256 d17a5eaa5ec2d39b46b3f57162ef1d9b2fc735b672e7922cd1dc38048b14efa8
MD5 de419db1accbcd966c6418617f36313d
BLAKE2b-256 7d938238b56cbb7a0ae4c8a564818b41b7558eb93e1beb15adef755e3dc2383b

See more details on using hashes here.

File details

Details for the file traceai_langchain-0.1.10-py3-none-any.whl.

File metadata

  • Download URL: traceai_langchain-0.1.10-py3-none-any.whl
  • Upload date:
  • Size: 14.0 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_langchain-0.1.10-py3-none-any.whl
Algorithm Hash digest
SHA256 6a675e3105fb02fb93d35be0c6edafb145018ba7f8cd5598b18b4a8076ce1276
MD5 2c5befe5e55d067eee10e96ffa844266
BLAKE2b-256 87cc37e5a6fb52e2c8c5480f2b0870eeede55981caa195b4dd8f958282a3f3ff

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