AgentSkillsCN

api-tracing

使用跨度和分布式追踪对API请求进行仪表化。在跟踪请求延迟或调试API问题时使用。

SKILL.md
--- frontmatter
name: api-tracing
description: Instrument API requests with spans and distributed tracing. Use when tracking request latency or debugging API issues.
triggers:
  - "API tracing"
  - "track API requests"
  - "distributed tracing"
priority: 2

API Tracing

Measure API requests and correlate with backend traces.

What to Capture (OTel-Compatible)

AttributeOTel NamePurpose
Methodhttp.request.methodGET, POST, etc.
Statushttp.response.status_codeSuccess/failure
URLurl.pathEndpoint (sanitized)
Durationhttp.request.durationRequest time (ms)

Using OTel naming now = easier migration later.

Key Thresholds

MetricGoodAcceptablePoor
p50<200ms<500ms>500ms
p95<1s<2s>2s
Error rate<0.1%<1%>1%

What NOT to Log

Don'tWhy
Request bodiesPII risk
Auth headersSecurity
Full response dataSize limits
User tokensSecurity

Do log: Request ID, sanitized path, status code, duration, error type.

Implementation

See templates/api-interceptor.ts for fetch/axios interceptors.

Use Read tool to load template when generating implementation.

Related

  • skills/error-tracking - API error handling
  • skills/route-transition-tracking - Data fetch during navigation
  • references/otel-web.md - OpenTelemetry naming