Documentation Index
Fetch the complete documentation index at: https://docs.getnetra.ai/llms.txt
Use this file to discover all available pages before exploring further.
Installation
Install both the Netra SDK and LangChain:
pip install netra-sdk langchain langchain-openai
Usage
Initialize the Netra SDK to automatically trace all LangChain operations:
from netra import Netra
from langchain_openai import ChatOpenAI
import os
# Initialize Netra
Netra.init(
headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
trace_content=True
)
# Use LangChain as normal - automatically traced
model = ChatOpenAI(temperature=0.9)
response = model.invoke("Tell me a joke")
Chains
Trace LangChain chains with custom workflow decorators:
from netra.decorators import workflow, span
from langchain_openai import ChatOpenAI
from langchain.prompts import PromptTemplate
model = ChatOpenAI()
@workflow()
def summarize_chain(text: str):
prompt = PromptTemplate.from_template(
"Summarize this text: {text}"
)
chain = prompt | model
return chain.invoke({"text": text})
result = summarize_chain("Long article text...")
Trace LangChain agents with custom span creation:
from netra.decorators import agent, task
from netra import SpanWrapper
from langchain_openai import ChatOpenAI
from langchain.agents import create_react_agent, AgentExecutor
from langchain.tools import Tool
model = ChatOpenAI()
@agent()
def run_agent(query: str):
span = SpanWrapper("agent-execution").start()
try:
agent_executor = create_react_agent(
llm=model,
tools=[calculator_tool]
)
result = agent_executor.invoke({"input": query})
span.end()
return result
except Exception as e:
span.set_attribute("error", str(e))
span.end()
raise
Streaming Responses
The SDK automatically captures streaming outputs from LangChain:
from netra.decorators import task
@task()
def stream_response(query: str):
model = ChatOpenAI(streaming=True)
for chunk in model.stream(query):
print(chunk.content, end="", flush=True)
Selective Instrumentation
Control which integrations are enabled:
from netra import Netra
from netra.instrumentation.instruments import InstrumentSet
# Only enable specific instruments
Netra.init(
headers=f"x-api-key={os.environ.get('NETRA_API_KEY')}",
instruments={InstrumentSet.OPENAI}
)
Next Steps