| name | sentry-setup |
| description | Integrate and manage Sentry error tracking: SDK setup in Go and JavaScript, source maps, releases, performance tracing, error grouping. Trigger: when setting up Sentry, sentry-cli releases, sentry source maps, Sentry SDK integration, Sentry error tracking, Sentry performance monitoring |
| version | 1 |
| argument-hint | [releases|sourcemaps|dsn|performance|go|javascript] |
| allowed-tools | ["bash","read","write","grep","glob"] |
Sentry Error Tracking and Monitoring
You are now operating in Sentry integration mode.
Installation
brew install getsentry/tools/sentry-cli
npm install -g @sentry/cli
curl -sL https://sentry.io/get-cli/ | bash
sentry-cli --version
sentry-cli login
Configuration
export SENTRY_AUTH_TOKEN="sntrys_your_auth_token_here"
export SENTRY_ORG="your-org-slug"
export SENTRY_PROJECT="your-project-slug"
export SENTRY_DSN="https://key@sentry.io/project-id"
Release Management
sentry-cli releases new "1.2.3"
sentry-cli releases set-commits "1.2.3" --auto
sentry-cli releases set-commits "1.2.3" \
--commit "your-org/your-repo@abc123..def456"
sentry-cli releases finalize "1.2.3"
sentry-cli releases deploys "1.2.3" new \
--env production \
--name "deploy-$(date +%Y%m%dT%H%M%S)"
sentry-cli releases list
sentry-cli releases delete "1.2.3"
Source Maps (JavaScript/TypeScript)
sentry-cli sourcemaps upload \
--release "1.2.3" \
--url-prefix "~/static/js" \
./dist/
sentry-cli sourcemaps inject ./dist/
sentry-cli sourcemaps upload ./dist/ --release "1.2.3"
sentry-cli sourcemaps explain --release "1.2.3" --url "~/static/js/main.js"
sentry-cli releases files "1.2.3" upload-sourcemaps ./dist \
--url-prefix "~/static/js" \
--rewrite
Vite + Sentry Example
import { sentryVitePlugin } from "@sentry/vite-plugin";
export default {
plugins: [
sentryVitePlugin({
org: process.env.SENTRY_ORG,
project: process.env.SENTRY_PROJECT,
authToken: process.env.SENTRY_AUTH_TOKEN,
sourcemaps: {
assets: "./dist/**",
ignore: ["./node_modules/**"],
},
release: {
name: process.env.RELEASE_VERSION,
inject: true,
},
}),
],
build: {
sourcemap: true,
},
};
Go SDK Integration
go get github.com/getsentry/sentry-go
package main
import (
"log"
"time"
"github.com/getsentry/sentry-go"
)
func main() {
err := sentry.Init(sentry.ClientOptions{
Dsn: "https://key@sentry.io/project-id",
Environment: "production",
Release: "myapp@1.2.3",
TracesSampleRate: 0.1,
AttachStacktrace: true,
Debug: false,
})
if err != nil {
log.Fatalf("sentry.Init: %v", err)
}
defer sentry.Flush(2 * time.Second)
sentry.CaptureMessage("application started")
}
func processOrder(orderID string) error {
err := db.FindOrder(orderID)
if err != nil {
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetTag("order_id", orderID)
scope.SetLevel(sentry.LevelError)
sentry.CaptureException(err)
})
return err
}
return nil
}
func sentryMiddleware(next http.Handler) http.Handler {
return sentryhttp.New(sentryhttp.Options{
Repanic: true,
}).Handle(next)
}
JavaScript/TypeScript SDK Integration
npm install @sentry/browser @sentry/tracing
npm install @sentry/react
import * as Sentry from "@sentry/browser";
Sentry.init({
dsn: "https://key@sentry.io/project-id",
environment: import.meta.env.MODE,
release: import.meta.env.VITE_RELEASE_VERSION,
integrations: [
Sentry.browserTracingIntegration(),
Sentry.replayIntegration({
maskAllText: true,
blockAllMedia: true,
}),
],
tracesSampleRate: 0.1,
replaysSessionSampleRate: 0.01,
replaysOnErrorSampleRate: 1.0,
});
try {
riskyOperation();
} catch (err) {
Sentry.withScope((scope) => {
scope.setTag("feature", "checkout");
scope.setUser({ id: userId, email: userEmail });
Sentry.captureException(err);
});
}
Sentry.addBreadcrumb({
category: "user-action",
message: "Clicked submit button",
level: "info",
});
Performance Tracing
ctx := sentry.StartTransaction(context.Background(), "process-order")
defer ctx.Finish()
span := sentry.StartSpan(ctx, "db.query", sentry.WithDescription("SELECT orders"))
defer span.Finish()
const transaction = Sentry.startTransaction({ name: "checkout" });
const span = transaction.startChild({ op: "db", description: "fetchCart" });
try {
const cart = await db.fetchCart(userId);
span.setStatus("ok");
} catch (err) {
span.setStatus("internal_error");
Sentry.captureException(err);
} finally {
span.finish();
transaction.finish();
}
Error Grouping and Fingerprinting
sentry.WithScope(func(scope *sentry.Scope) {
scope.SetFingerprint([]string{"database-connection-error", "postgres"})
sentry.CaptureException(err)
})
Sentry.withScope((scope) => {
scope.setFingerprint(["payment-gateway-timeout", gateway]);
Sentry.captureException(err);
});
CI/CD Integration
RELEASE="${GITHUB_REF_NAME}-${GITHUB_SHA:0:8}"
sentry-cli releases new "$RELEASE"
sentry-cli releases set-commits "$RELEASE" --auto
sentry-cli sourcemaps inject ./dist/
sentry-cli sourcemaps upload ./dist/ --release "$RELEASE"
sentry-cli releases finalize "$RELEASE"
sentry-cli releases deploys "$RELEASE" new --env production
Troubleshooting
sentry-cli info
sentry-cli releases files "1.2.3" list
curl -X POST "https://sentry.io/api/<project-id>/store/" \
-H "X-Sentry-Auth: Sentry sentry_version=7, sentry_key=<key>" \
-H "Content-Type: application/json" \
-d '{"message":"test","level":"error","platform":"javascript"}'
sentry-cli --log-level debug releases new "test"
Best Practices
- Always call
sentry.Flush(2 * time.Second) at program exit in Go to ensure buffered events are sent.
- Set
environment in SDK init (production, staging, development) — this enables filtering in the Sentry UI.
- Set
release in SDK init to correlate errors with specific code versions.
- Use
TracesSampleRate less than 1.0 in production to control costs (start at 0.1).
- Never log or print the DSN in application output — treat it as a semi-secret.
- Use
scope.SetUser() for PII-compliant user context (id only, not email, in GDPR regions).
- Upload source maps in CI as part of the release pipeline — never skip this step.
- Use
sentry-cli releases set-commits --auto only when CI has git history (use fetch-depth: 0 in GitHub Actions).