> ## Documentation Index
> Fetch the complete documentation index at: https://docs.galileo.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Google ADK (OpenTelemetry)

> Learn how to integrate a Google ADK project with Galileo using OpenTelemetry and OpenInference

Galileo supports logging traces from Google ADK applications using OpenTelemetry and OpenInference.

<Tip>
  For a simpler integration with automatic tracing, consider using the [native Galileo-adk package](/sdk-api/third-party-integrations/google-adk/google-adk-native) instead.
</Tip>

## Set up OpenTelemetry

To log Google ADK agents using OpenInference, the first step is to set up OpenTelemetry.

<Steps>
  <Step title="Installation">
    Add the OpenTelemetry packages to your project:

    <CodeGroup>
      ```bash Terminal theme={null}
      pip install opentelemetry-api opentelemetry-sdk \
                  opentelemetry-exporter-otlp
      ```
    </CodeGroup>

    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.
  </Step>

  <Step title="Create environment variables for your Galileo settings">
    Set environment variables for your Galileo settings, for example in a `.env` file.
    These environment variables are consumed by the `GalileoSpanProcessor`to authenticate
    and route traces to the correct Galileo Project and Log stream:

    {/*<!-- markdownlint-enable MD044 -->*/}

    <CodeGroup>
      ```ini .env theme={null}
      # 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 "

      # Provide the console url below if you are using a
      # custom deployment, and not using the free tier, or app.galileo.ai.
      # This will look something like “console.galileo.yourcompany.com”.
      # GALILEO_CONSOLE_URL="your-galileo-console-url"
      ```
    </CodeGroup>
  </Step>

  <Step title="Self hosted deployments: Set the OTel endpoint">
    <Note>
      Skip this step if you are using Galileo Cloud.
    </Note>

    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:

    * **Galileo Cloud** at [app.galileo.ai](https://app.galileo.ai), then you don't need to provide a custom OTel endpoint.
      The default endpoint `https://api.galileo.ai/otel/traces` will be used automatically.

    * 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 `GALILEO_CONSOLE_URL` environment variable. For example:

    <CodeGroup>
      ```python Python theme={null}
      os.environ["GALILEO_CONSOLE_URL"] = "https://api.galileo.ai"
      ```
    </CodeGroup>
  </Step>

  <Step title="Initialize and create the Galileo span processor">
    The `GalileoSpanProcessor` automatically configures authentication
    and metadata using your environment variables. It also:

    * Auto-builds OTLP headers using your Galileo credentials
    * Configures the correct OTLP trace endpoint
    * Registers a batch span processor that exports traces to Galileo

    <CodeGroup>
      ```python Python theme={null}
      from galileo import otel  

      # GalileoSpanProcessor (no manual OTLP config required) loads the env vars for 
      # the Galileo API key, Project, and Log stream. Make sure to set them first. 
      galileo_span_processor = otel.GalileoSpanProcessor(
          # Optional parameters if not set, uses env var
          # project=os.environ["GALILEO_PROJECT"], 
          # logstream=os.environ.get("GALILEO_LOG_STREAM"),  
      )
      ```
    </CodeGroup>
  </Step>

  <Step title="Register the span processor">
    The span processor can now be registered with an OTel trace provider.

    <CodeGroup>
      ```python Python theme={null}
      from opentelemetry.sdk import trace as trace_sdk

      tracer_provider = trace_sdk.TracerProvider()
      tracer_provider.add_span_processor(span_processor)
      ```
    </CodeGroup>
  </Step>
</Steps>

## Log a Google ADK agent using OpenInference

Once OpenTelemetry is configured, you can use OpenInference to log traces.

<Steps>
  <Step title="Install the Google ADK OpenInference support">
    To support OpenInference with the Google ADK, you need to install the OpenInference instrumentor.

    <CodeGroup>
      ```bash Terminal theme={null}
      pip install openinference-instrumentation-google-adk
      ```
    </CodeGroup>
  </Step>

  <Step title="Configure the instrumentor">
    You can now create a `GoogleADKInstrumentor` instance and instrument it with the trace provider you created earlier.

    <CodeGroup>
      ```python Python theme={null}
      from openinference.instrumentation.google_adk import GoogleADKInstrumentor

      GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)
      ```
    </CodeGroup>

    When you run your Google ADK code, traces will be logged to Galileo.
  </Step>
</Steps>

## Full example

Here is a full example based off the [Google ADK quickstart](https://google.github.io/adk-docs/get-started/python/#create-an-agent-project). You can find this project in the [Galileo SDK examples repo](https://github.com/rungalileo/sdk-examples/tree/main/python/agent/google-adk).

To run this example, create a `.env` file with the following values set, or set them as environment variables:

```ini .env theme={null}
# AWS environment variables
GOOGLE_API_KEY=your-google-api-key

# 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](https://app.galileo.ai/settings/api-keys), Google API key, [Galileo OTel endpoint](/sdk-api/third-party-integrations/opentelemetry-and-openinference#configure-the-otel-endpoint), project name, and Log stream name.

<CodeGroup>
  ```python Python theme={null}
  import os

  # Google ADK imports
  from google.adk.agents.llm_agent import Agent

  # OpenTelemetry imports
  from opentelemetry.sdk import trace as trace_sdk
  from opentelemetry.sdk.trace.export import BatchSpanProcessor
  from opentelemetry.exporter.otlp.proto.http.trace_exporter import (
      OTLPSpanExporter
  )

  # OpenInference imports for Google ADK instrumentation
  from openinference.instrumentation.google_adk import (
      GoogleADKInstrumentor
  )

  # Load the Galileo API configuration from .env file
  from dotenv import load_dotenv
  load_dotenv()

  # Configure the OTel endpoint environment variable
  os.environ["OTEL_EXPORTER_OTLP_TRACES_ENDPOINT"] = os.environ.get(
      "GALILEO_API_ENDPOINT", 
      "https://api.galileo.ai/otel/traces"
  )

  # Create the headers using the Galileo API key, project, and log stream
  headers = {
     "Galileo-API-Key": os.getenv("GALILEO_API_KEY"),
     "project": os.getenv("GALILEO_PROJECT"),
     "logstream": os.getenv("GALILEO_LOG_STREAM")
  }

  # Store the headers in the appropriate environment variable
  os.environ['OTEL_EXPORTER_OTLP_HEADERS'] = ",".join(
      [f"{k}={v}" for k, v in headers.items()]
  )

  # Create and configure the OTLP span exporter
  exporter = OTLPSpanExporter()
  tracer_provider = trace_sdk.TracerProvider()
  tracer_provider.add_span_processor(BatchSpanProcessor(exporter))

  # Instrument the Google ADK with OpenTelemetry
  GoogleADKInstrumentor().instrument(tracer_provider=tracer_provider)

  # The following code is the example quickstart from the
  # Google ADK documentation
  # Mock tool implementation
  def get_current_time(city: str) -> dict:
      """Returns the current time in a specified city."""
      return {"status": "success", "city": city, "time": "10:30 AM"}

  # Agent definition
  root_agent = Agent(
      model='gemini-2.5-flash',
      name='root_agent',
      description="Tells the current time in a specified city.",
      instruction="""
  You are a helpful assistant that tells the current time in cities.
  Use the 'get_current_time' tool for this purpose.
  """,
      tools=[get_current_time],
  )
  ```
</CodeGroup>
