> ## Documentation Index
> Fetch the complete documentation index at: https://arizeai-433a7140.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Google ADK tracing for Java

> Instrument Google ADK for Java with OpenInference and export traces to Phoenix.

Google ADK creates OpenTelemetry spans. The OpenInference Java agent enriches those spans and sends them to Phoenix without changes to your agent code.

## Prerequisites

* Java and Gradle
* A [Gemini API key](https://aistudio.google.com/app/apikey)
* The shaded OpenInference ADK Java agent JAR

## Run the example

<Card>
  <Tabs>
    <Tab title="Local">
      ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
      uvx arize-phoenix serve
      ```

      No [uv](https://docs.astral.sh/uv/)? `pip install arize-phoenix && phoenix serve` does the same thing. See [Terminal setup](/docs/phoenix/environments#terminal) for customization.
    </Tab>

    <Tab title="Container">
      ```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
      docker run -p 6006:6006 -p 4317:4317 arizephoenix/phoenix:latest
      ```

      Images are published to [Docker Hub](https://hub.docker.com/r/arizephoenix/phoenix). See [Docker](/docs/phoenix/self-hosting/deployment-options/docker) for volumes, PostgreSQL, and other options.
    </Tab>

    <Tab title="Self-Host">
      Run Phoenix on your own infrastructure, backed by PostgreSQL so traces persist beyond a single process. This is the option to reach for once Phoenix is shared across a team or environment.

      The [self-hosting guide](/docs/phoenix/self-hosting) covers [Kubernetes](/docs/phoenix/self-hosting/deployment-options/kubernetes), [Helm](/docs/phoenix/self-hosting/deployment-options/kubernetes-helm), [Railway](/docs/phoenix/self-hosting/deployment-options/railway), [AWS CloudFormation](/docs/phoenix/self-hosting/deployment-options/aws-with-cloudformation), [Google Cloud Run](/docs/phoenix/self-hosting/deployment-options/google-cloud-run), [Azure](/docs/phoenix/self-hosting/deployment-options/azure), and [Render](/docs/phoenix/self-hosting/deployment-options/render), plus authentication and configuration.
    </Tab>
  </Tabs>

  Phoenix serves its UI and OTLP HTTP on port **6006**, and OTLP gRPC on port **4317**. For a local instance that's [http://localhost:6006](http://localhost:6006) — leave it running while you work.
</Card>

The [Phoenix example](https://github.com/Arize-ai/phoenix/tree/main/java/examples/google-adk) includes the ADK agent, OpenTelemetry configuration, and Gradle launch task. Set the path to your shaded OpenInference agent JAR, then run it:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
export GOOGLE_API_KEY="your-key"
export OPENINFERENCE_ADK_AGENT_JAR="/path/to/adk-agent.jar"
cd java/examples/google-adk
gradle -PagentJar="$OPENINFERENCE_ADK_AGENT_JAR" run
```

Open Phoenix and select the `google-adk-java` project.

## Instrument your application

Register a global OpenTelemetry SDK with an OTLP exporter and the `openinference.project.name` resource attribute. Do this before constructing any ADK object because ADK captures the global OpenTelemetry instance when its telemetry class loads. The following is taken from the example's [`WeatherAgent.java`](https://github.com/Arize-ai/phoenix/blob/main/java/examples/google-adk/src/main/java/com/arize/phoenix/examples/adk/WeatherAgent.java):

```java theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
Resource resource = Resource.getDefault().merge(Resource.create(Attributes.of(
    AttributeKey.stringKey("openinference.project.name"), "google-adk-java"
)));

OtlpGrpcSpanExporter exporter = OtlpGrpcSpanExporter.builder()
    .setEndpoint(System.getenv().getOrDefault(
        "OTEL_EXPORTER_OTLP_ENDPOINT", "http://localhost:4317"))
    .build();

SdkTracerProvider tracerProvider = SdkTracerProvider.builder()
    .setResource(resource)
    .addSpanProcessor(BatchSpanProcessor.builder(exporter).build())
    .build();

OpenTelemetrySdk.builder()
    .setTracerProvider(tracerProvider)
    .buildAndRegisterGlobal();

// Construct and run ADK objects after registration.
```

Launch your application with the shaded agent JAR:

```bash theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
java \
  -javaagent:/path/to/adk-agent.jar \
  -cp "your-application-classpath" \
  com.example.Main
```

For Phoenix Cloud or an authenticated deployment, follow [Connect your app to Phoenix](/docs/phoenix/tracing/how-to-tracing/setup-tracing) to configure the endpoint and headers.

<Tip>
  For short-lived applications, flush and shut down the tracer provider before the process exits.
</Tip>

## Resources

<CardGroup cols={2}>
  <Card title="Complete Java example" href="https://github.com/Arize-ai/phoenix/tree/main/java/examples/google-adk" icon="github" />

  <Card title="OpenInference ADK Java agent" href="https://github.com/Arize-ai/openinference/tree/main/java/instrumentation/openinference-instrumentation-adk-java" icon="github" />
</CardGroup>
