Skip to main content
Galileo supports logging traces from Strands Agents SDK applications using OpenTelemetry.

Set up OpenTelemetry

To log Strands Agents using Galileo, the first step is to set up OpenTelemetry.
1

Installation

Add the OpenTelemetry packages to your project:
pip install opentelemetry-api opentelemetry-sdk \
            opentelemetry-exporter-otlp
The opentelemetry-api and opentelemetry-sdk packages provide the core OpenTelemetry functionality. The opentelemetry-exporter-otlp package enables sending traces to Galileo’s OTLP endpoint.
2

Create environment variables for your Galileo settings

Set environment variables for your Galileo settings, for example in a .env file:
# Your Galileo API key
GALILEO_API_KEY="your-galileo-api-key"

# Your Galileo project name
GALILEO_PROJECT="your-galileo-project-name"

# The name of the Log stream you want to use for logging
GALILEO_LOG_STREAM="your-galileo-log-stream "
3

Get the authentication headers

The OTel headers is a dictionary containing your API key, project name, and Log stream name. The convention for OTel is to store this header as a single string of key=value pairs in the OTEL_EXPORTER_OTLP_HEADERS environment variable.
import os

# Create a dictionary of headers
headers = {
    "Galileo-API-Key": os.environ.get("GALILEO_API_KEY"),
    "project": os.environ.get("GALILEO_PROJECT"),
    "logstream": os.environ.get("GALILEO_LOG_STREAM", "default"),
}

# Set this as an environment variable
os.environ["OTEL_EXPORTER_OTLP_TRACES_HEADERS"] = ",".join(
    [f"{k}={v}" for k, v in headers.items()]
)
4

Get your endpoint

The OTel endpoint is different from Galileo’s regular API endpoint and is specifically designed to receive telemetry data in the OTLP format.If you are using app.galileo.ai, then the OTel endpoint is https://api.galileo.ai/otel/traces.If you’re using a self-hosted Galileo deployment, replace the https://api.galileo.ai/otel/traces endpoint with your deployment URL. The format of this URL is based on your console URL, replacing console with api and appending /otel/traces.For example:
  • if your console URL is https://console.galileo.example.com, the OTel endpoint would be https://api.galileo.example.com/otel/traces
  • if your console URL is https://console-galileo.apps.mycompany.com, the OTel endpoint would be https://api-galileo.apps.mycompany.com/otel/traces
The convention is to store this in the OTEL_EXPORTER_OTLP_ENDPOINT environment variable. For example:
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = \
    "https://api.galileo.ai/otel/traces"

Log a Strands ADK agent using OpenTelemetry

Once OpenTelemetry is configured, you can use the OTel capabilities of Strands to log traces.
1

Import the Strands Agent telemetry package

The Strands Agents SDK has telemetry support out of the box. Start by importing StrandsTelemetry with the following code:
from strands.telemetry import StrandsTelemetry
2

Set up the exporter

You can now set up an OTel exporter for your Strands Agent:
strands_telemetry = StrandsTelemetry()
strands_telemetry.setup_otlp_exporter()
When you run your Strands Agent code, traces will be logged to Galileo.

Full example

Here is a full example based off the Strands Agent quickstart. You can find this project in the Galileo SDK examples repo. To run this example, create a .env file with the following values set, or set them as environment variables:
.env
# AWS environment variables
AWS_BEARER_TOKEN_BEDROCK=your-aws-bedrock-token

# Galileo environment variables
GALILEO_API_ENDPOINT=your-galileo-otel-api-endpoint
GALILEO_API_KEY=your-galileo-api-key
GALILEO_PROJECT=your-galileo-project
GALILEO_LOG_STREAM=your-log-stream
Remember to update these to match your Galileo API key, AWS Bedrock token, Galileo OTel endpoint, project name, and Log stream name.
import os

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 Galileo OTel API endpoint for OTel
# Export the Galileo OTel API endpoint for OTel
os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.environ.get(
    "GALILEO_API_ENDPOINT", 
    "https://api.galileo.ai/otel/traces"
)

# Export the Galileo OTel headers pointing to the correct API key,
# # project, and log stream
headers = {
    "Galileo-API-Key": os.environ["GALILEO_API_KEY"],
    "project": os.environ["GALILEO_PROJECT"],
    "logstream": os.environ["GALILEO_LOG_STREAM"],
}

os.environ["OTEL_EXPORTER_OTLP_HEADERS"] = ",".join(
    [f"{k}={v}" for k, v in headers.items()]
)

# Setup telemetry for the Strands agent using Galileo as the OTel backend
strands_telemetry = StrandsTelemetry()
strands_telemetry.setup_otlp_exporter()

# Define a custom tool as a Python function using the @tool decorator
@tool
def letter_counter(word: str, letter: str) -> int:
    """
    Count occurrences of a specific letter in a word.

    Args:
        word (str): The input word to search in
        letter (str): The specific letter to count

    Returns:
        int: The number of occurrences of the letter in the word
    """
    if not isinstance(word, str) or not isinstance(letter, str):
        return 0

    if len(letter) != 1:
        raise ValueError("The 'letter' parameter must be a single char")

    return word.lower().count(letter.lower())


# Create an agent with tools from the community-driven strands-tools
# package as well as our custom letter_counter tool
agent = Agent(tools=[calculator, current_time, letter_counter])

# Ask the agent a question that uses the available tools
message = """
I have 4 requests:

1. What is the time right now?
2. Calculate 3111696 / 74088
3. Tell me how many letter R's are in the word "strawberry" 🍓
"""
agent(message)