계측

계측 (Instrumentation)

Instrumentation은 에이전트 런을 OpenTelemetry 트레이싱으로 계측하는 캐퍼빌리티예요. 런 자체, 각 모델 요청, 각 도구 실행에 대해 OpenTelemetry Semantic Conventions for Generative AI를 따르는 스팬(span)을 만듭니다. Pydantic Logfire (또는 아무 OTel 백엔드)와 함께 쓰면 에이전트가 무엇을 하는지 완전히 파악할 수 있어요.

출처: 문서

본문

import logfire

from pydantic_ai import Agent
from pydantic_ai.capabilities import Instrumentation

logfire.configure()  # (1)

agent = Agent('openai:gpt-5.2', capabilities=[Instrumentation()])
  • (1) Instrumentation이 기본으로 사용하는 전역 TracerProvider를 설정합니다. 다른 OpenTelemetry SDK 설정도 모두 동작해요.

InstrumentationSettingsInstrumentation(settings=...)로 전달하면 공급자, 콘텐츠 캡처, 컨벤션 버전을 커스터마이즈할 수 있어요. 캐퍼빌리티를 에이전트마다 붙이는 대신 애플리케이션의 모든 에이전트를 계측하려면 Agent.instrument_all()을 사용하세요.

다른 캐퍼빌리티는 OpenTelemetry API(opentelemetry.trace.get_current_span().set_attribute(...))를 통해 만들어진 스팬에 속성을 붙일 수 있어요.

전체 가이드는 Debugging and Monitoring에서 확인하세요: 설정, 캡처되는 내용, 시맨틱 컨벤션 버전, 민감하거나 바이너리 콘텐츠 제외 방법까지.

더 알아보기 (Learn more)