Skip to main content
LangSmith는 OpenTelemetry 통합을 통해 Google Agent Development Kit(ADK) 애플리케이션 추적을 지원합니다. 이 가이드에서는 Google ADK 에이전트에서 추적을 자동으로 캡처하여 모니터링 및 분석을 위해 LangSmith로 전송하는 방법을 설명합니다.

설치

선호하는 패키지 매니저를 사용하여 필요한 패키지를 설치하세요:
pip install langsmith google-adk
최적의 OpenTelemetry 지원을 위해서는 LangSmith Python SDK 버전 langsmith>=0.4.26이 필요합니다.

설정

1. 환경 변수 구성

LangSmith API 키와 프로젝트 이름을 설정하세요:
export LANGSMITH_API_KEY=<your_langsmith_api_key>
export LANGSMITH_PROJECT=<your_project_name>

2. OpenTelemetry 통합 구성

Google ADK 애플리케이션에서 LangSmith OpenTelemetry 통합을 가져와 구성하세요. 이렇게 하면 OpenTelemetry용 Google ADK 스팬이 자동으로 계측됩니다.
from langsmith.integrations.otel import configure

# LangSmith 추적 구성
configure(project_name="adk-example")  # 선택사항: LANGSMITH_PROJECT 및 LANGSMITH_API_KEY 환경 변수를 사용할 수도 있습니다
또는 Openinference GoogleADKInstrumentor를 사용할 수 있습니다:
from langsmith.integrations.otel import configure
from openinference.instrumentation.google_adk import GoogleADKInstrumentor

# LangSmith 추적 구성
configure(project_name="adk-example")

# Google ADK를 직접 계측
GoogleADKInstrumentor().instrument()
OpenTelemetry 환경 변수를 설정하거나 내보내기를 수동으로 구성할 필요가 없습니다. configure()가 모든 것을 자동으로 처리합니다.

3. ADK 에이전트 생성 및 실행

구성이 완료되면 Google ADK 애플리케이션이 자동으로 LangSmith로 추적을 전송합니다: 다음 예제는 에이전트, 세션, 러너를 설정한 다음 메시지를 보내고 이벤트를 스트리밍하는 최소한의 앱을 포함합니다.
import asyncio
from langsmith.integrations.otel import configure
from google.adk import Runner
from google.adk.agents import LlmAgent
from google.adk.sessions import InMemorySessionService
from google.genai import types

# LangSmith 추적 구성
configure(project_name="travel-assistant")

# 도구 정의
def get_flight_info(destination: str, departure_date: str) -> dict:
    """목적지에 대한 항공편 정보를 가져옵니다."""
    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:
    """도시에 대한 호텔 추천을 가져옵니다."""
    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():
    # ADK 에이전트 생성
    agent = LlmAgent(
        name="travel_assistant",
        tools=[get_flight_info, get_hotel_recommendations],
        model="gemini-2.5-flash-lite",
        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
    )

    # 세션 생성
    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
    )

    # 에이전트에게 메시지 전송
    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",
    )

    # 에이전트 실행 및 이벤트 처리
    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())

LangSmith에서 추적 보기

  • 에이전트 대화: 사용자와 ADK 에이전트 간의 완전한 대화 흐름
  • 도구 호출: 에이전트가 수행한 개별 함수 호출
  • 모델 상호작용: Gemini 모델을 사용한 LLM 요청 및 응답
  • 세션 정보: 관련 추적을 구성하기 위한 사용자 및 세션 컨텍스트
실행의 원시 입력 및 추적 정보가 포함된 LangSmith 대시보드.

고급 사용법

커스텀 메타데이터 및 태그

ADK 애플리케이션에서 스팬 속성을 설정하여 추적에 커스텀 메타데이터를 추가할 수 있습니다:
from opentelemetry import trace

# 현재 추적기 가져오기
tracer = trace.get_tracer(__name__)

async def main():
    with tracer.start_as_current_span("travel_booking_session") as span:
        # 커스텀 메타데이터 추가
        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.5-flash-lite",
            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
        )

        # ADK 워크플로우 계속
        # ...

Connect these docs programmatically to Claude, VSCode, and more via MCP for real-time answers.
I