Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion examples/agent/google-adk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ SPLUNK_AO_PROJECT=
SPLUNK_AO_LOG_STREAM=
```

For the `SPLUNK_AO_API_ENDPOINT`, this is different to the console URL that you would normally use. If you are using `app.galileo.ai` for example, the endpoint is `https://api.galileo.ai/otel/traces`.
For the `SPLUNK_AO_API_ENDPOINT`, this is different to the console URL that you would normally use. If you are using `app.galileo.ai` for example, the endpoint is `https://api.galileo.ai/otel/v1/traces`.

See the [Splunk AO OTel and OpenInference documentation](https://docs.galileo.ai/sdk-api/third-party-integrations/opentelemetry-and-openinference) for more details.

Expand Down
2 changes: 1 addition & 1 deletion examples/agent/langgraph-open-telemetry/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies = [
"langgraph-prebuilt>=0.6.0",
"openai",
"python-dotenv>=1.1.0",
"splunk-ao[otel]",
"splunk-ao",
"opentelemetry-instrumentation-langchain>=0.48.1",
"opentelemetry-instrumentation-openai-v2>=2.1b0",
]
Expand Down
51 changes: 17 additions & 34 deletions examples/agent/langgraph-otel/main.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import os
from typing import TypedDict

# Load environment variables first (contains API keys and project settings)
import dotenv
import openai
from langgraph.graph import END, StateGraph
from openinference.instrumentation.langchain import LangChainInstrumentor
from openinference.instrumentation.openai import OpenAIInstrumentor
from opentelemetry import trace as trace_api # API for interacting with traces
from opentelemetry.exporter.otlp.proto.http.trace_exporter import OTLPSpanExporter # Sends traces via HTTP
from opentelemetry.sdk import trace as trace_sdk # SDK for creating traces
from opentelemetry.sdk.resources import Resource
from opentelemetry.sdk.trace.export import BatchSpanProcessor # Efficiently batches spans before export

# Load environment variables first (contains API keys and project settings)
dotenv.load_dotenv()

# ============================================================================
Expand All @@ -13,27 +22,6 @@
# traces, metrics, and logs from your applications. Think of it as a way to
# "instrument" your code so you can see exactly what's happening during execution.

# Core OpenTelemetry imports
from opentelemetry.sdk import trace as trace_sdk # SDK for creating traces
from opentelemetry import trace as trace_api # API for interacting with traces
from opentelemetry.sdk.trace.export import (
BatchSpanProcessor,
) # Efficiently batches spans before export
from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
OTLPSpanExporter,
) # Sends traces via HTTP

# OpenInference is a specialized instrumentation library that understands AI frameworks
# It automatically creates meaningful spans for LangChain/LangGraph operations
from openinference.instrumentation.langchain import LangChainInstrumentor
from openinference.instrumentation.openai import OpenAIInstrumentor

# LangGraph imports - this is what we're actually instrumenting
from langgraph.graph import StateGraph, END

# OpenAI imports for LLM integration
import openai

# ============================================================================
# STEP 1: CONFIGURE API AUTHENTICATION
# ============================================================================
Expand Down Expand Up @@ -75,16 +63,14 @@
# Splunk AO's OTel ingest lives on the `api.` subdomain (not the `console.`/`app.`
# one you log into). We derive it from SPLUNK_AO_CONSOLE_URL so custom deployments
# (e.g. https://console.demo-v2.galileocloud.io/) route to their own ingest
# (https://api.demo-v2.galileocloud.io/otel/traces) instead of app.galileo.ai.
# (https://api.demo-v2.galileocloud.io/otel/v1/traces) instead of app.galileo.ai.
console_url = os.environ.get("SPLUNK_AO_CONSOLE_URL", "https://app.galileo.ai").rstrip("/")
api_url = console_url.replace("://console.", "://api.").replace("://app.", "://api.")
endpoint = f"{api_url}/otel/traces"
endpoint = f"{api_url}/otel/v1/traces"
print(f"OTEL endpoint: {endpoint}")

# Create a TracerProvider with descriptive resource information
# This helps identify these traces as coming from OpenTelemetry in Splunk AO
from opentelemetry.sdk.resources import Resource

resource = Resource.create(
{
"service.name": "LangGraph-OpenTelemetry-Demo",
Expand Down Expand Up @@ -143,7 +129,7 @@ class AgentState(TypedDict, total=False):

# Node 1: Input Validation
# Validates and prepares the user input for processing
def validate_input(state: AgentState):
def validate_input(state: AgentState) -> AgentState:
user_input = state.get("user_input", "")
print(f"📥 Validating input: '{user_input}'")

Expand All @@ -160,18 +146,15 @@ def validate_input(state: AgentState):
# Node 2: Generate Response
# Calls OpenAI to generate a response to the user's question
# OpenAI instrumentation will automatically create detailed spans
def generate_response(state: AgentState):
def generate_response(state: AgentState) -> AgentState:
user_input = state["user_input"]

try:
print(f"⚙️ Calling OpenAI with: '{user_input}'")

# Make the OpenAI API call - OpenAI instrumentation handles tracing
response = client.chat.completions.create(
model="gpt-3.5-turbo",
messages=[{"role": "user", "content": user_input}],
max_tokens=300,
temperature=0.7,
model="gpt-3.5-turbo", messages=[{"role": "user", "content": user_input}], max_tokens=300, temperature=0.7
)

# Extract the response content
Expand All @@ -183,12 +166,12 @@ def generate_response(state: AgentState):

except Exception as e:
print(f"❌ Error calling OpenAI: {e}")
return {"llm_response": f"Error: {str(e)}"}
return {"llm_response": f"Error: {e!s}"}


# Node 3: Format Answer
# Extracts and formats a clean answer from the raw LLM response
def format_answer(state: AgentState):
def format_answer(state: AgentState) -> AgentState:
llm_response = state.get("llm_response", "")

# Simple parsing - extract first sentence for a concise answer
Expand Down
2 changes: 1 addition & 1 deletion examples/agent/microsoft-agent-framework/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
agent-framework>=1.0.0b251120
splunk-ao[otel]
splunk-ao
pydantic
2 changes: 1 addition & 1 deletion examples/agent/pydantic-ai-support-agent/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ description = "An example project for using Splunk AO with PydanticAI."
readme = "README.md"
requires-python = ">=3.11, <3.14"
dependencies = [
"splunk-ao[otel]",
"splunk-ao",
"pydantic-ai>=1.0.0",
]
2 changes: 1 addition & 1 deletion examples/agent/startup-simulator-3000/test_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import os
import sys
from importlib.metadata import version, PackageNotFoundError
from importlib.metadata import PackageNotFoundError, version

from dotenv import load_dotenv

Expand Down
9 changes: 5 additions & 4 deletions examples/agent/strands-agents/agent.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
import os

# Load environment variables from the .env file
from dotenv import load_dotenv
from strands import Agent, tool
from strands.telemetry import StrandsTelemetry
from strands_tools import calculator, current_time

# Load environment variables from the .env file
from dotenv import load_dotenv

load_dotenv(override=True)

# Export the Splunk AO OTel API endpoint for OTel
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.environ.get("SPLUNK_AO_API_ENDPOINT", "https://api.galileo.ai/otel/traces")
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.environ.get(
"SPLUNK_AO_API_ENDPOINT", "https://api.galileo.ai/otel/v1/traces"
)

# Export the Splunk AO OTel headers pointing to the correct API key, project, and log stream
headers = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ uvicorn==0.34.0
openai==1.82.0
langgraph==0.4.1
chromadb-client==0.6.3
splunk-ao[otel]
splunk-ao
opentelemetry-api
opentelemetry-sdk
opentelemetry-exporter-otlp-proto-http
Expand Down
Loading
Loading