LangSmith supports tracing Google Agent Development Kit (ADK) applications through the OpenTelemetry integration. This guide shows you how to automatically capture traces from your Google ADK agents and send them to LangSmith for monitoring and analysis.
In your Google ADK application, import and configure the LangSmith OpenTelemetry integration. This will automatically instrument Google ADK spans for OpenTelemetry.
Copy
Ask AI
from langsmith.integrations.otel import configure# Configure LangSmith tracingconfigure(project_name="adk-example") # Optional: can also use LANGSMITH_PROJECT and LANGSMITH_API_KEY environment variables
Alternatively, you can use the Openinference GoogleADKInstrumentor:
Copy
Ask AI
from langsmith.integrations.otel import configurefrom openinference.instrumentation.google_adk import GoogleADKInstrumentor# Configure LangSmith tracingconfigure(project_name="adk-example")# Instrument Google ADK directlyGoogleADKInstrumentor().instrument()
You do not need to set any OpenTelemetry environment variables or configure exporters manually—configure() handles everything automatically.
Once configured, your Google ADK application will automatically send traces to LangSmith:This example includes a minimal app that sets up an agent, session, and runner, then sends a message and streams events.
Copy
Ask AI
import asynciofrom langsmith.integrations.otel import configurefrom google.adk import Runnerfrom google.adk.agents import LlmAgentfrom google.adk.sessions import InMemorySessionServicefrom google.genai import types# Configure LangSmith tracingconfigure(project_name="travel-assistant")# Define your toolsdef get_flight_info(destination: str, departure_date: str) -> dict: """Get flight information for a destination.""" return { "destination": destination, "departure_date": departure_date, "price": "$450", "duration": "5h 30m", "airline": "Example Airways" }def get_hotel_recommendations(city: str, check_in: str) -> dict: """Get hotel recommendations for a city.""" return { "city": city, "check_in": check_in, "hotels": [ {"name": "Grand Plaza Hotel", "rating": 4.5, "price": "$120/night"}, {"name": "City Center Inn", "rating": 4.2, "price": "$95/night"} ] }async def main(): # Create your ADK agent agent = LlmAgent( name="travel_assistant", tools=[get_flight_info, get_hotel_recommendations], model="gemini-2.0-flash-exp", instruction="You are a helpful travel assistant that can help with flights and hotels.", ) # Set up session service and runner session_service = InMemorySessionService() runner = Runner( app_name="travel_app", agent=agent, session_service=session_service ) # Create a session user_id = "traveler_456" session_id = "session_789" await session_service.create_session( app_name="travel_app", user_id=user_id, session_id=session_id ) # Send a message to the agent new_message = types.Content( parts=[types.Part(text="I need to book a flight to Paris for March 15th and find a good hotel.")], role="user", ) # Run the agent and process events events = runner.run( user_id=user_id, session_id=session_id, new_message=new_message, ) for event in events: print(event)if __name__ == "__main__": asyncio.run(main())
You can add custom metadata to your traces by setting span attributes in your ADK application:
Copy
Ask AI
from opentelemetry import trace# Get the current tracertracer = trace.get_tracer(__name__)async def main(): with tracer.start_as_current_span("travel_booking_session") as span: # Add custom metadata span.set_attribute("langsmith.metadata.user_type", "premium") span.set_attribute("langsmith.metadata.booking_source", "mobile_app") span.set_attribute("langsmith.span.tags", "travel,booking,premium") agent = LlmAgent( name="travel_assistant", tools=[get_flight_info, get_hotel_recommendations], model="gemini-2.0-flash-exp", instruction="You are a helpful travel assistant that can help with flights and hotels.", ) session_service = InMemorySessionService() runner = Runner( app_name="travel_app", agent=agent, session_service=session_service ) # Continue with your ADK workflow # ...