OpenTelemetry로 MCP 트래픽 모니터링
OpenTelemetry로 MCP 트래픽 모니터링 (Monitor MCP traffic with OpenTelemetry)
이 문서는 AI Gateway에서 MCP 도구 트래픽을 OpenTelemetry로 모니터링하는 방법을 단계별로 안내해요. OpenTelemetry Policy를 AI MCP Server 엔티티에 연결하면 도구 호출 횟수, 응답 크기, 요청 소요 시간 같은 지표가 코드 변경 없이 자동으로 수집돼요. kongctl로 Policy를 붙이고 MCP 트래픽을 생성한 뒤, 로컬 OpenTelemetry Collector에서 메트릭을 확인하고 리소스를 정리하는 과정까지 살펴봐요
출처: 문서
본문
TL;DR
AI Gateway에서 MCP 도구 트래픽은 어떻게 모니터링하나요? MCP 도구 트래픽을 모니터링하려면 OpenTelemetry Policy를 AI MCP Server 엔티티에 연결하세요. AI Gateway가 도구 호출 횟수, 응답 크기, 요청 소요 시간 같은 메트릭을 코드 변경 없이 자동으로 옵저버빌리티 백엔드로 전송해요.
이 튜토리얼에서는 kongctl로 Policy를 연결하는 방법, MCP 트래픽을 생성하는 방법, 그리고 로컬 OpenTelemetry Collector에서 결과 메트릭을 확인하는 방법을 알아봐요.
사전 준비
시리즈 사전 준비
이 페이지는 RESTful API를 MCP 도구로 매핑하고 MCP 트래픽 관찰하기 시리즈의 일부예요.
이 페이지를 진행하기 전에 이전 페이지인 RESTful API를 MCP 도구로 매핑하기를 먼저 완료하세요.
kongctl v1.20.2+
이 튜토리얼은 Konnect 리소스를 프로그래밍 방식으로 관리할 때 kongctl을 사용해요. kongctl은 항상 최신 버전(1.20.2)을 유지하는 것을 추천해요.
-
developer.konghq.com/kongctl에서 kongctl을 설치하세요.
-
설치를 확인하세요:
kongctl version
OpenTelemetry Collector
백그라운드에서 4318 포트로 리스닝하는 로컬 OpenTelemetry Collector를 실행하세요:
docker run -d \
--name otel-collector \
--network kong-ai-quickstart-net \
-p 127.0.0.1:4318:4318 \
otel/opentelemetry-collector:0.141.0
{:data-test-prereq="block"}
MCP Server 엔티티에 OpenTelemetry Policy 연결하기
기본적으로 AI Policy는 AI Gateway의 모든 리소스에 적용돼요. global을 false로 설정하면 이 동작이 바뀌어요. otel-mcp Policy가 모든 엔티티에 적용되는 대신, 이 Policy를 명시적으로 나열한 엔티티에만 효과가 발휘돼요.
petstore-mcp 엔티티는 policies 목록에서 otel-mcp를 참조하는 방식으로 이를 설정해요. 그 결과 petstore-mcp를 거치는 모든 요청이 측정되고, 앞서 실행해 둔 컬렉터로 메트릭 형태로 내보내져요. resource_attributes 아래의 service.name 값은 내보낸 데이터에 붙는 라벨이에요. 따라서 같은 컬렉터에 여러 AI Gateway나 서비스를 운영 중이라면 특정 메트릭이 어느 것에서 왔는지 구별할 수 있어요.
kongctl apply -f - --auto-approve --pat "$KONNECT_TOKEN" << 'EOF'
ai_gateway_policies:
- ref: otel-mcp
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
name: otel-mcp
display_name: "otel-mcp"
type: opentelemetry
enabled: true
global: false
config:
traces_endpoint: http://otel-collector:4318/v1/traces
metrics:
endpoint: http://otel-collector:4318/v1/metrics
enable_ai_metrics: true
resource_attributes:
service.name: kong-mcp
ai_gateway_mcp_servers:
- ref: petstore-mcp
ai_gateway: !lookup {id: !env AI_GATEWAY_ID}
name: petstore-mcp
display_name: "Petstore API"
type: conversion-listener
enabled: true
policies:
- !ref otel-mcp#name
access:
acl_attribute_type: consumer
acls:
allow: []
default_tool_acls:
deny: []
config:
url: http://host.docker.internal:8080/api/v3
route:
paths:
- /petstore
logging:
payloads: false
server:
timeout: 60000
tools:
- name: get-pets-by-status
description: Find pets by status
method: GET
path: /petstore/pet/findByStatus
parameters:
- name: status
in: query
required: true
schema:
type: string
enum:
- available
- pending
- sold
description: Status value to filter pets by
- name: get-pet-by-id
description: Get a pet by ID
method: GET
path: /petstore/pet/{petId}
parameters:
- description: ID of the pet to retrieve
in: path
name: petId
required: true
schema:
type: integer
EOF
{: data-test-step="block" }
MCP 트래픽 생성하기
이제 get-pet-by-id 도구를 호출해서 Dog 1(id:4)의 상세 정보를 확인할 수 있어요:
npx -y @modelcontextprotocol/inspector@0.22.0 --cli \
http://localhost:8000/petstore \
--transport http --method tools/call \
--tool-name get-pet-by-id \
--tool-arg path_petId=4 | jq -r '.content[0].text' | jq -c '.'
다음과 같은 응답이 보일 거예요:
{"id":4,"category":{"id":1,"name":"Dogs"},"name":"Dog 1","photoUrls":["url1","url2"],"tags":[{"id":1,"name":"tag1"},{"id":2,"name":"tag2"}],"status":"available"}
{:.no-copy-code .wrap}
메트릭 검증하기
내보내진 메트릭을 확인하려면 컬렉터 로그에서 kong.gen_ai.mcp를 찾아보세요:
트래픽 생성 후에는 컬렉터가 메트릭을 내보낼 때까지 몇 초 정도 기다려 주세요.
docker logs otel-collector 2>&1 | grep -A 15 kong.gen_ai.mcp
다음과 같은 데이터가 보일 거예요:
Metric #8
Descriptor:
-> Name: kong.gen_ai.mcp.response.size
-> Description: Size of AI MCP response body
-> Unit: By
-> DataType: Histogram
-> AggregationTemporality: Cumulative
HistogramDataPoints #0
Data point attributes:
-> kong.workspace.name: Str(default)
-> kong.route.name: Str(petstore-mcp-route)
-> mcp.method.name: Str(tools/call)
-> gen_ai.tool.name: Str(get-pet-by-id)
-> kong.service.name: Str(petstore-mcp)
Count: 1
Sum: 2175.000000
Metric #10
Descriptor:
-> Name: mcp.server.operation.duration
-> Description: MCP request/notification duration as observed on the receiver
-> Unit: s
-> DataType: Histogram
-> AggregationTemporality: Cumulative
HistogramDataPoints #3
Data point attributes:
-> gen_ai.operation.name: Str(execute_tool)
-> kong.workspace.name: Str(default)
-> kong.route.name: Str(petstore-mcp-route)
-> mcp.method.name: Str(tools/call)
-> gen_ai.tool.name: Str(get-pet-by-id)
-> kong.service.name: Str(petstore-mcp)
Count: 1
Sum: 0.037000
{:.collapsible .no-copy-code}
kong.route.name에 -route 접미사가 붙는 이유는 AI Gateway가 MCP Server 엔티티를 위해 Route를 자동 생성하기 때문이에요.
전체 메트릭 레퍼런스는 MCP 메트릭을 참고하세요.
Konnect의 MCP 메트릭
컬렉터를 설정하지 않고도 Konnect Analytics로 MCP 트래픽 메트릭을 볼 수 있어요:
- Observability > Dashboards로 이동하세요.
- Create dashboard > Create from template을 클릭하세요.
- Agentic analytics 대시보드를 선택하세요. 이 대시보드는 어떤 도구가 가장 자주 호출되는지 보여주고, 컨슈머별 도구 사용량을 분석하며, 시간에 따른 도구별 평균 지연 시간을 추적해요. 덕분에 MCP 지원 서비스를 운영하는 팀이 사용 패턴을 이해하고 성능 병목 지점을 파악하는 데 도움을 받을 수 있어요.
- Use template을 클릭하면 MCP 도구 사용량, 총 MCP 요청 수, 총 MCP 오류 수 등 다른 통계를 볼 수 있어요.
정리
OpenTelemetry Collector 중지하기
docker rm -f otel-collector
{: data-test-cleanup="block" }
Petstore API 중지하기
docker rm -f swagger-petstore
{: data-test-cleanup="block" }
AI Gateway 리소스 정리하기
이 가이드에서 생성한 모든 AI Gateway 리소스를 정리하려면 다음을 실행하세요:
curl -Ls https://get.konghq.com/ai | bash -s -- -d
관련 리소스
더 알아보기 (Learn more)
- 트레이스와 메트릭을 수집·내보내는 OpenTelemetry Policy의 설정 방법을 설명해요 — OpenTelemetry Policy
- MCP 도구를 노출하는 AI MCP Server 엔티티의 구성 방법을 다뤄요 — AI MCP Server
- 이 튜토리얼이 속한 시리즈의 전체 흐름을 안내해요 — Map a RESTful API to MCP tools and observe MCP traffic
- 수집되는 MCP 관련 메트릭의 종류와 의미를 설명해요 — MCP metrics
- Konnect 리소스를 프로그래밍 방식으로 관리하는 CLI 도구 사용법을 소개해요 — kongctl