Send your GenAI traces to Sumo Logic with OpenLLMetry
The Sumo Logic AI Observability app reads OpenLLMetry traces, which follow the OpenTelemetry GenAI semantic conventions (gen_ai.*) and add traceloop.* attributes. Any library that emits gen_ai.* span attributes works, and you don't need a Sumo Logic agent or SDK.
Get started with OpenLLMetry instrumentation
Use either OpenLLMetry or OpenTelemetry instrumentation method per process. Running both can generate duplicate spans.
| Category | OpenLLMetry |
|---|---|
| Overview | Open-source Traceloop SDK built on OpenTelemetry. |
| Setup | Python: install the SDK and initialize it with Traceloop.init(). Node.js: register the OpenLLMetry instrumentation packages with the OpenTelemetry SDK. |
| Prompt and response capture | Enabled by default. |
| Best suited for | Broad provider and framework coverage with minimal code. |
Tested providers and frameworks
The following providers and frameworks have been tested with OpenLLMetry. Any provider or framework that OpenLLMetry instruments and that emits gen_ai.* span attributes works with the app.
| Vendor | OpenLLMetry |
|---|---|
| Google Gemini | Yes |
| Groq | Yes |
| LangChain and LangGraph | Yes |
| LlamaIndex | Yes |
| Haystack | Yes |
| OpenAI and AI gateways: Helicone, OpenRouter, Braintrust | Yes |
How to instrument your LLM application?
Prerequisites
- Create a Sumo Logic OTLP/HTTP source and copy its source URL. The URL contains the authentication token, so you don't need to set headers or API keys.
- Use Python 3.10 or later, or Node.js 22.15 or later.
- Use one virtual environment (Python) or one project (Node.js) per method. Don't install OpenTelemetry and OpenLLMetry instrumentation together.
Instrument your application
You can use Python or Node.js to instrument your LLM application directly with OpenLLMetry. Each tab starts with its own exporter setup, which the examples in that tab assume has run first.
- Python
- Node.js
Set up the exporter for Python
Do this once per application. Every example below assumes it has run first, so none of them repeats it.
-
Set the following environment variables, along with your LLM provider's API key. Use the same source URL value as the OpenTelemetry method:
export TRACELOOP_BASE_URL="<YOUR_SOURCE_URL>"export OTEL_SERVICE_NAME="<YOUR_SERVICE_NAME>"export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=<YOUR_ENVIRONMENT>"export TRACELOOP_METRICS_ENABLED=false # Sumo Logic drops OTLP histogram metrics, so send traces onlyOTEL_SERVICE_NAMEbecomes the service filter in the dashboards, anddeployment.environmentbecomes the environment filter. -
Install the SDK:
pip install "traceloop-sdk>=0.62.0" -
Initialize the SDK by adding the following code at the start of your application, before you import any LLM or framework library:
import osfrom traceloop.sdk import Traceloop# Endpoint comes from TRACELOOP_BASE_URL. Service name and deployment.environment# come from OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES.Traceloop.init(app_name=os.getenv("OTEL_SERVICE_NAME"),api_endpoint=os.getenv("TRACELOOP_BASE_URL"),telemetry_enabled=False, # don't send anonymous SDK usage data to Traceloop) -
Flush spans before the process exits. OpenLLMetry has no public
flush(), but it registers the global provider:from opentelemetry import tracetrace.get_tracer_provider().shutdown()In a long-running service, skip the shutdown call. Spans are sent in batches.
Google Gemini
Traces content generation, including streamed calls, made with the Google GenAI SDK (google-genai), for both the Gemini Developer API and Vertex AI.
Gemini spans use the operation name generate_content, not chat.
Install:
pip install "traceloop-sdk>=0.62.0" google-genai
Run the following code after the Python exporter setup:
import os
from google import genai
client = genai.Client() # reads GEMINI_API_KEY
response = client.models.generate_content(
model="gemini-2.5-flash",
contents="What is 15 multiplied by 7?",
)
print(response.text)
The provider is reported as gcp.gen_ai.
Additional resources:
Groq
Traces chat completions sent to Groq.
Install:
pip install "traceloop-sdk>=0.62.0" groq
Run the following code after the Python exporter setup:
import os
from groq import Groq
client = Groq() # reads GROQ_API_KEY
response = client.chat.completions.create(
model="openai/gpt-oss-20b",
messages=[{"role": "user", "content": "What is 15 multiplied by 7?"}],
max_tokens=100,
)
print(response.choices[0].message.content)
Uses the native Groq SDK, so the provider is reported correctly as groq.
Additional resources:
LangChain and LangGraph
Traces agents, chains, chat models, and tool calls. One package covers both LangChain and LangGraph. The example is a tool-calling agent: each run appears as a LangGraph.workflow span with invoke_agent, execute_task, ChatOpenAI.chat, and execute_tool child spans.
Install:
pip install "traceloop-sdk>=0.62.0" "langchain<2" langchain-openai
Run the following code after the Python exporter setup:
import os
from langchain_core.tools import tool
from langchain_openai import ChatOpenAI
from langchain.agents import create_agent
@tool
def multiply(a: int, b: int) -> int:
"""Multiply two integers."""
return a * b
agent = create_agent(ChatOpenAI(model="gpt-4o-mini"), tools=[multiply]) # reads OPENAI_API_KEY
from traceloop.sdk.tracing import set_conversation_id
set_conversation_id("session-123") # sets gen_ai.conversation.id on the spans that follow
result = agent.invoke({"messages": [("user", "What is 15 multiplied by 7?")]})
print(result["messages"][-1].content)
OpenLLMetry emits an execute_task span for each LangGraph node. A plain LangChain chain appears as a RunnableSequence.workflow span with execute_task and ChatOpenAI.chat child spans.
LangGraph's thread_id doesn't set the conversation ID with OpenLLMetry. Call set_conversation_id() instead. For more information, see Track conversations.
Additional resources:
LlamaIndex
Traces the LLM calls made by LlamaIndex query engines and agents. Each query appears as an openai.chat span. OpenLLMetry doesn't emit separate retrieval spans; to trace retrieval, use the OpenTelemetry method.
Install:
pip install "traceloop-sdk>=0.62.0" llama-index-core llama-index-llms-openai llama-index-embeddings-openai
Run the following code after the Python exporter setup:
import os
from llama_index.core import Document, Settings, VectorStoreIndex
from llama_index.embeddings.openai import OpenAIEmbedding
from llama_index.llms.openai import OpenAI
Settings.llm = OpenAI(model="gpt-4o-mini") # reads OPENAI_API_KEY
Settings.embed_model = OpenAIEmbedding(model="text-embedding-3-small")
index = VectorStoreIndex.from_documents([
Document(text="Sumo Logic accepts OpenTelemetry traces over OTLP/HTTP."),
Document(text="The AI Observability app reads gen_ai.* span attributes."),
])
print(index.as_query_engine().query("How do I send LLM traces to Sumo Logic?"))
Additional resources:
Haystack
Traces Haystack pipelines and the LLM calls their components make.
Install:
pip install "traceloop-sdk>=0.62.0" "haystack-ai>=2.11,<3"
haystack-ai 3.x isn't supported by the OpenLLMetry Haystack instrumentor.
Run the following code after the Python exporter setup:
import os
from haystack import Pipeline
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
pipeline = Pipeline()
pipeline.add_component("prompt_builder", ChatPromptBuilder())
pipeline.add_component("llm", OpenAIChatGenerator(model="gpt-4o-mini")) # reads OPENAI_API_KEY
pipeline.connect("prompt_builder.prompt", "llm.messages")
result = pipeline.run({"prompt_builder": {
"template": [ChatMessage.from_user("What is {{ a }} multiplied by {{ b }}?")],
"template_variables": {"a": 15, "b": 7},
}})
print(result["llm"]["replies"][0].text)
Additional resources:
OpenAI and AI gateways
Traces calls made with the OpenAI Python SDK, directly or through an OpenAI-compatible gateway. To use a gateway, set base_url to it.
The provider is reported as openai. Use the Gateway/API Base Distribution panel, which reads server.address, to split traffic by gateway.
Related sources:
Install:
pip install "traceloop-sdk>=0.62.0" openai
Run the following code after the Python exporter setup:
import os
from openai import OpenAI
# Pick your gateway's base URL and key:
# Helicone https://gateway.helicone.ai/api/v1 (plus a Helicone-Auth header)
# OpenRouter https://openrouter.ai/api/v1
# Braintrust https://api.braintrust.dev/v1/proxy
client = OpenAI(api_key=os.environ["OPENROUTER_API_KEY"], base_url="https://openrouter.ai/api/v1")
response = client.chat.completions.create(
model="openai/gpt-4o-mini",
messages=[{"role": "user", "content": "What is 15 multiplied by 7?"}],
max_tokens=100,
)
print(response.choices[0].message.content)
For Helicone, also pass the Helicone key and the provider to forward to:
client = OpenAI(
api_key=os.environ["OPENROUTER_API_KEY"],
base_url="https://gateway.helicone.ai/api/v1",
default_headers={
"Helicone-Auth": f"Bearer {os.environ['HELICONE_API_KEY']}",
"Helicone-Target-Url": "https://openrouter.ai",
},
)
Additional resources:
Track conversations in Python (optional)
The Conversation Analytics dashboard and the conversation_id filter require gen_ai.conversation.id on each LLM span. Use one ID for every call in the same chat or session. Don't include personal data.
Import set_conversation_id from traceloop.sdk.tracing, then call set_conversation_id("<ID>") before your LLM calls.
Other providers in Python (optional)
If OpenLLMetry doesn't cover your provider, call Traceloop.init() as in the Python exporter setup, and then set the gen_ai.* attributes on your own span:
from opentelemetry import trace
tracer = trace.get_tracer(__name__)
with tracer.start_as_current_span("chat my-model", kind=trace.SpanKind.CLIENT) as span:
span.set_attribute("gen_ai.operation.name", "chat")
span.set_attribute("gen_ai.provider.name", "my-provider")
span.set_attribute("gen_ai.request.model", "my-model")
response = call_my_model(prompt)
span.set_attribute("gen_ai.usage.input_tokens", response.input_tokens)
span.set_attribute("gen_ai.usage.output_tokens", response.output_tokens)
span.set_attribute("gen_ai.response.finish_reasons", [response.finish_reason])
For every attribute, see GenAI client spans and GenAI agent spans.
Set up the exporter for Node.js
Do this once per application. Every example below assumes it has run first. In Node.js, OpenLLMetry is a set of instrumentation packages that you register with the OpenTelemetry SDK. There is no Traceloop.init().
-
Set the following environment variables, along with your LLM provider's API key:
export OTEL_EXPORTER_OTLP_ENDPOINT="<YOUR_SOURCE_URL>"export OTEL_SERVICE_NAME="<YOUR_SERVICE_NAME>"export OTEL_RESOURCE_ATTRIBUTES="deployment.environment=<YOUR_ENVIRONMENT>"OTEL_SERVICE_NAMEbecomes the service filter in the dashboards, anddeployment.environmentbecomes the environment filter. -
Install the OpenTelemetry SDK. Use these versions, because the OpenLLMetry packages need the 3.x SDK line:
npm install @opentelemetry/api@1.10.0 @opentelemetry/sdk-trace@3.1.1 \@opentelemetry/context-async-hooks@3.1.1 @opentelemetry/core@3.1.1 \@opentelemetry/resources@3.1.1 @opentelemetry/exporter-trace-otlp-proto@0.301.2 \@opentelemetry/instrumentation@0.301.2 -
Add the following code at the start of your application, before you load any LLM or framework library. These packages patch a library when it is first loaded, so a client created earlier isn't traced:
const { trace, context, propagation } = require("@opentelemetry/api");const { TracerProvider, BatchSpanProcessor } = require("@opentelemetry/sdk-trace");const { AsyncLocalStorageContextManager } = require("@opentelemetry/context-async-hooks");const { CompositePropagator, W3CTraceContextPropagator, W3CBaggagePropagator } = require("@opentelemetry/core");const { OTLPTraceExporter } = require("@opentelemetry/exporter-trace-otlp-proto");const { detectResources, envDetector } = require("@opentelemetry/resources");const { registerInstrumentations } = require("@opentelemetry/instrumentation");// Prompts and responses are captured by default. Set TRACELOOP_TRACE_CONTENT=false to turn them off.const traceContent = process.env.TRACELOOP_TRACE_CONTENT !== "false";// Endpoint, service.name and deployment.environment come from the// OTEL_EXPORTER_OTLP_ENDPOINT, OTEL_SERVICE_NAME and OTEL_RESOURCE_ATTRIBUTES env vars.const provider = new TracerProvider({resource: detectResources({ detectors: [envDetector] }),spanProcessors: [new BatchSpanProcessor({ exporter: new OTLPTraceExporter() })],});trace.setGlobalTracerProvider(provider);context.setGlobalContextManager(new AsyncLocalStorageContextManager().enable()); // spans nest through async callspropagation.setGlobalPropagator(new CompositePropagator({ propagators: [new W3CTraceContextPropagator(), new W3CBaggagePropagator()] })); -
Flush spans before the process exits. This matters for short-lived scripts:
await provider.shutdown();In CommonJS, top-level
awaitfails when this snippet runs on its own. Call it from inside an async function, as the examples below do. Alternatively, use this form:provider.shutdown().then(() => process.exit(0));In a long-running service, skip the shutdown call. Spans are sent in batches.
Each example below starts with a Traces content generation, including streamed calls and chats, made with the Google GenAI SDK ( Only Install: Run the following code after the Node.js exporter setup: Gemini spans use the operation name Additional resources: There is no OpenLLMetry package for the native Additional resources: Traces chains, chat models, and tool calls. One package covers both LangChain and LangGraph, and it works with any provider package that LangChain wraps, such as Install: Run the following code after the Node.js exporter setup: A plain LangChain chain appears as Tool spans are named Don't also enable the OpenAI instrumentation in the same process. A Additional resources: Traces LlamaIndex.TS query engines and chat engines. Each query appears as a Install: Run the following code after the Node.js exporter setup: The embedding calls made while building the index aren't traced. Only the query-time embedding is. Calls made through the Groq provider are reported with the provider Additional resources: Traces chat completions and Responses API calls made with the OpenAI Node.js SDK, directly or through an OpenAI-compatible gateway. To use a gateway, set Only Related sources: Install: Run the following code after the Node.js exporter setup: The provider is reported as This package doesn't trace embedding calls or failed calls, such as an unknown model, and streamed calls report no token usage. To trace those, use the OpenTelemetry method. Additional resources:registerInstrumentations call that you add after this setup and before you load the library.Google Gemini
@google/genai).@google/genai 1.x is supported. Version 2.0 and later, and the older @google/generative-ai package, produce no spans.npm install @traceloop/instrumentation-google-generativeai@0.27.0 "@google/genai@1"generate_content, not chat. The provider is reported as gcp.gen_ai. Embedding calls (embedContent) aren't traced.Groq
groq-sdk, so calls made with it aren't traced. Use one of these instead:
ChatGroq (@langchain/groq). The LangChain and LangGraph example below traces it with no other change.https://api.groq.com/openai/v1. See the OpenAI and AI gateways example below.LangChain and LangGraph
@langchain/openai, @langchain/anthropic, and @langchain/groq. The example is a tool-calling agent: each run produces workflow spans, a chat span for each model call, and an execute_tool span for each tool call.npm install @traceloop/instrumentation-langchain@0.27.0 @langchain/core @langchain/openai @langchain/langgraph zodworkflow spans for each step and a chat <model> span for the model call.execute_tool DynamicStructuredTool, not after your tool. The package doesn't set gen_ai.conversation.id, and LangGraph's thread_id doesn't set it either, so the Conversation Analytics dashboard has nothing to group by.ChatOpenAI call can then produce two chat spans and count its tokens twice.LlamaIndex
retriever_query_engine.query workflow span with retrieve, synthesize, and chat child spans. Each chat turn appears as a context_chat_engine.chat span.npm install @traceloop/instrumentation-llamaindex@0.27.0 llamaindex @llamaindex/openaiopenai.OpenAI and AI gateways
baseURL to it.openai 4.x to 6.x is supported. Version 7 and later produces no spans.npm install @traceloop/instrumentation-openai@0.27.0 "openai@6"openai for every gateway, and the spans don't carry server.address, so the Gateway/API Base Distribution panel can't split traffic by gateway.
Track conversations in Nodejs (optional)
The Conversation Analytics dashboard and the conversation_id filter require gen_ai.conversation.id on each LLM span. Use one ID for every call in the same chat or session. Don't include personal data.
The Node.js instrumentation packages don't set this attribute. To add it, make these two changes to the Node.js exporter setup:
-
Add a context key and a helper, before you create the
TracerProvider:const { createContextKey } = require("@opentelemetry/api");const CONVERSATION_KEY = createContextKey("conversation_id");const runWithConversation = (id, fn) => context.with(context.active().setValue(CONVERSATION_KEY, id), fn); -
Add a span processor to the
spanProcessorslist. It copies the ID onto every span that starts insiderunWithConversation:spanProcessors: [{onStart(span, ctx) {const id = ctx.getValue(CONVERSATION_KEY);if (id) span.setAttribute("gen_ai.conversation.id", id);},onEnd() {},forceFlush: () => Promise.resolve(),shutdown: () => Promise.resolve(),},new BatchSpanProcessor({ exporter: new OTLPTraceExporter() }),],
Then wrap the calls that belong to one conversation:
await runWithConversation("session-123", async () => {
// every LLM call in here, including the ones LangChain or LlamaIndex make internally,
// gets gen_ai.conversation.id = "session-123"
await agent.invoke({ messages: [{ role: "user", content: "What is 15 multiplied by 7?" }] });
});
Spans created outside the wrapper have no conversation ID. LangGraph's thread_id doesn't set it either.
Other providers in Nodejs (optional)
If OpenLLMetry doesn't cover your provider or SDK, create a span yourself with the @opentelemetry/api tracer, which the Node.js exporter setup already installs, and set the gen_ai.* attributes on it:
const { trace, SpanKind } = require("@opentelemetry/api");
const tracer = trace.getTracer("my-app");
const response = await tracer.startActiveSpan("chat my-model", { kind: SpanKind.CLIENT }, async (span) => {
span.setAttribute("gen_ai.operation.name", "chat");
span.setAttribute("gen_ai.provider.name", "my-provider");
span.setAttribute("gen_ai.request.model", "my-model");
try {
const response = await callMyModel(prompt);
span.setAttribute("gen_ai.usage.input_tokens", response.inputTokens);
span.setAttribute("gen_ai.usage.output_tokens", response.outputTokens);
span.setAttribute("gen_ai.response.finish_reasons", [response.finishReason]);
return response;
} catch (err) {
span.recordException(err);
span.setStatus({ code: 2, message: String(err) }); // 2 = ERROR
throw err;
} finally {
span.end();
}
});
For every attribute, see GenAI client spans and GenAI agent spans.
Optional settings
Capture prompts and responses
Prompts and responses can contain personal data, credentials, or regulated data. Review your data-handling policies before you capture them in production.
Content is the text your application exchanges with the model:
- Prompts and system instructions.
- Model responses.
- Tool call arguments and results.
Only the Prompt and Response Analytics dashboard and the tool input and output panels use content. All other panels work without it.
OpenLLMetry captures content by default. To turn it off, set TRACELOOP_TRACE_CONTENT=false. See OpenLLMetry privacy.
Verify data collection
Run your application, send a few requests, and then run this log search in Sumo Logic:
_index=_trace_spans service="<YOUR_SERVICE_NAME>"
Within a few minutes, you should see one row per provider, model, and operation. Then open any AI Observability dashboard and select your service in the service filter.