sentry-instrumentation-guide

작성자: sentry

코드를 계측할 때 어떤 Sentry 신호를 사용할지 결정하세요 — 오류, 스팬, 스팬 속성, 로그 또는 메트릭. 계측을 추가할 때 확실하지 않을 때 사용하세요…

npx skills add https://github.com/getsentry/sentry-for-ai --skill sentry-instrumentation-guide

All Skills > Feature Setup > Instrumentation Guide

Sentry Instrumentation Guide: When to Reach for What

Errors, traces, logs, and metrics are the four kinds of telemetry most apps run on, and they overlap enough that the choice is rarely obvious. You can stuff context into a span attribute instead of logging it. You can count log lines instead of emitting a metric. You can add a duration to a log and call it a span.

But each signal exists because it answers a different question and feeds a different workflow once it lands. Reaching for the wrong one means the data is technically there but useless for the job you actually have later. This skill is the decision framework: given a value or an event in front of you, which signal should carry it, and why.

It decides what to emit. For how to turn each pillar on for a given stack, hand off to the sentry-*-sdk skills and sentry-setup-ai-monitoring.

Invoke This Skill When

  • You're instrumenting a piece of code and unsure whether something should be a log, a span, a span attribute, or a metric
  • You're deciding "what to instrument where" across a service or request handler
  • You're reviewing existing instrumentation for gaps (e.g. an error feed that's empty while users report problems)
  • A coding agent needs a consistent rule for choosing between errors, traces, logs, and metrics

Important: The SDK APIs and code samples here are illustrative. Verify exact signatures and minimum versions against docs.sentry.io and the relevant sentry-*-sdk skill before implementing.

The Four Signals, One Question Each

SignalThe question it answersDocs
Errors"What just broke?" — a stack trace and exception type, grouped into a deduplicated Issue that gets assigned and tracked to resolution. If your code threw, it's an error.Issues
Traces"Did the request flow the way it was supposed to?" — a waterfall of timed spans. Mostly auto-instrumented.Trace Explorer
Logs"What was true at this point in the code, and why?" — the system's state at one moment as a structured event: config, flags, inputs/outputs, the decision that was made.Logs
Metrics"How's this trending over time?" — counters, gauges, distributions you can slice by attribute and chart, alert on, or compare across a deploy.Metrics

A useful mental split: a log is one request's story (the needle), a metric is the aggregate (whether the haystack is normal), a trace is where the time went, and an error is the thing that needs a stack trace and an owner.

The Decision Table

Use this as a gut check:

What you want to knowReach for
Something crashed, show the stack traceError
How long did this take? Which step is slow?Traces / Spans
Did the request flow through the steps I expected?Traces / Spans
What was the state when the code made this decision?Log
What did this function receive and return?Log
How often does X happen? Is the rate normal?Metric
Did something change after the deploy?Metric

Resolving the Overlaps

The same value can legitimately appear in more than one signal. These four tiebreakers cover almost every real case. (Full reasoning, gotchas, and the "why not just log everything / emit one wide event?" arguments live in references/choosing-signals.md.)

  • Span attribute or metric? Context about one request's flow that you want while reading that trace → span attribute (it rides on the span in the waterfall). A standalone value you want to chart, alert on, or slice over time across all requests → metric. The same number can warrant both: candidate_count on the span to read one request, recommendations.served as a metric to watch the rate.
  • Log or span? The span is the timed node in the flow (mostly auto-instrumented, you rarely write it). The log is the decision-point state inside that node (you always write it on purpose). Span answers where and how long; log answers what was true and why.
  • Log or metric? A log finds the one specific request that went wrong (the needle). A metric tells you how many requests went wrong (the haystack). Don't derive a rate by counting log lines — emit the metric directly.
  • Error or log? Needs a stack trace and should be tracked as an Issue → error. An unexpected-but-handled condition worth recording → log. Truly non-critical with a traceback → logger.warning(exc_info=True) keeps the trace in logs without creating noise in the error feed.

Sampling vs Filtering — Match Retention to the Question

Each signal's retention falls out of the question it answers:

  • Traces are sampled. You don't need every request to understand where time goes, so keep a representative slice via traces_sample_rate (higher in dev, lower in production).
  • Errors are captured by default. No sampling to think about for the baseline.
  • Logs and metrics are NOT sampled. You keep every one and filter instead, with before_send_log and before_send_metric. This is the point: the whole reason for a log is to find the one rare request that went sideways, and you can't find what you sampled away.

(For the exact sampling and filtering config in your language, see the matching SDK skill's references/tracing.md and references/metrics.md.)

Because all four signals come from one SDK, they share a trace_id and correlate on their own — every log and metric is tied to its trace, so you can drill from a metric spike straight into the samples behind it.

What Deliberate Instrumentation Looks Like

Roughly 80% of spans are auto-instrumented by your framework and database integrations — you write almost none of them. The deliberate work is the other 20%: a span attribute or two to enrich the flow, a decision-point log, and a metric, placed at the spots where your code makes a choice worth questioning later.

references/instrumentation-examples.md walks through a single request handler instrumented end to end, in both Python and JavaScript/TypeScript, showing the span attribute, the log, and the metric side by side on the same decision.

Handing Off to Setup

This skill tells you what to emit. To actually wire a pillar up:

  • Install the SDK and turn on tracing, logs, and metrics → the matching sentry-<platform>-sdk skill (e.g. sentry-python-sdk, sentry-nextjs-sdk, sentry-node-sdk). Each has per-feature reference files for tracing, logging, metrics, and more.
  • Instrument LLM / agent calls → sentry-setup-ai-monitoring.

Logs and metrics are the two pillars most projects haven't turned on yet, and both are included on every plan. If they aren't enabled, route to the SDK skill first, then come back here to decide what to put where.

sentry의 다른 스킬

add-ai-integration
sentry
Sentry JavaScript SDK에 새로운 AI 제공자 통합을 추가합니다. 새로운 AI 계측(OpenAI, Anthropic, Vercel AI, LangChain 등)을 기여할 때 사용하세요.
add-cdn-bundle
sentry
지정된 기능을 사용하여 브라우저 패키지용 새 CDN 번들을 생성합니다.
agent-prompt
sentry
효과적인 에이전트 프롬프트와 스킬 작성을 위한 참고 가이드입니다. 새로운 스킬을 만들거나 프롬프트 품질을 검토하거나 Warden의 프롬프트를 이해할 때 사용하세요.
agents-md
sentry
이 스킬은 사용자가 "AGENTS.md 생성", "AGENTS.md 업데이트", "에이전트 문서 유지", "CLAUDE.md 설정"을 요청하거나 에이전트를 유지해야 할 때 사용해야 합니다.
agents-md
sentry
60줄 미만의 최소화되고 핵심 정보를 담은 에이전트 문서를 생성 및 유지 관리합니다. 연구 기반의 에이전트 문서 모범 사례를 적용하며, 길이가 길어질수록 지침 품질이 저하됩니다. 패키지 관리자, 파일 범위 명령(파일별 테스트/린트/타입체크), 에이전트 ID를 포함한 커밋 속성의 세 가지 핵심 섹션이 필요합니다. 프로젝트 구조(잠금 파일, 린터 설정, CI 명령, 모노레포 표시)를 분석하여 파일에 포함할 내용을 결정합니다. 헤더와 불릿만 사용하며, 참조...
agents-md
sentry
이 스킬은 사용자가 "create AGENTS.md", "update AGENTS.md", "maintain agent docs", "set up CLAUDE.md"를 요청하거나 에이전트 문서를 유지해야 할 때 사용해야 합니다.
ai-sdk
sentry
ai-sdk — AI 에이전트용 설치 가능한 스킬, getsentry/webvitals.com에서 게시함.
analytics
sentry
Sentry의 프론트엔드 UI에서 analytics 이벤트를 계측하고 발견합니다. 버튼, 페이지, 모달 또는 사용자 정의 상호작용에 추적을 추가하거나 새로운 항목을 정의할 때 사용합니다.