sentry-architecture-variants
Configure Sentry error tracking and performance monitoring for different application architectures. Use when setting up Sentry for monoliths, microservices, serverless functions, event-driven systems, frontend SPAs, mobile apps, or hybrid deployments. Trigger: "sentry monolith setup", "sentry microservices tracing", "sentry serverless lambda", "sentry event-driven kafka", "sentry react native", "sentry architecture pattern".
What this skill does
# Sentry Architecture Variants
## Overview
Choose the right Sentry SDK, project layout, and tracing strategy for each
application architecture. Every pattern below uses Sentry SDK v8 APIs —
`@sentry/node`, `@sentry/browser`, `@sentry/react`, `@sentry/react-native`,
`@sentry/aws-serverless`, and `@sentry/google-cloud-serverless`. The goal is
one coherent trace from the user's device through every backend hop, regardless
of how many runtimes or deployment targets sit in between.
Deep-dive references for each pattern:
[Monolith](references/monolith-architecture.md) |
[Microservices](references/microservices-architecture.md) |
[Serverless](references/serverless-architecture.md) |
[Event-driven](references/event-driven-architecture.md) |
[Frontend SPA](references/frontend-spa-architecture.md) |
[Mobile](references/mobile-architecture.md) |
[Hybrid](references/hybrid-architecture.md) |
[Errors](references/errors.md)
## Prerequisites
- Node.js 18+ (or target platform runtime)
- Sentry organization with at least one project created at [sentry.io](https://sentry.io)
- `SENTRY_DSN` available as an environment variable (one per Sentry project)
- Application architecture documented — service inventory, deployment targets, team ownership mapped
- For distributed tracing: all inter-service transports identified (HTTP, gRPC, Kafka, SQS)
## Instructions
### Step 1 — Identify Your Architecture and Select SDK Packages
Map every runtime in your system to the correct Sentry SDK package and project layout.
| Architecture | SDK Package | Sentry Projects | Key Integration |
|---|---|---|---|
| Monolith | `@sentry/node` | 1 project, env tags | Module tags + ownership rules |
| Microservices | `@sentry/node` (per service) | 1 project per service | Distributed tracing via headers |
| Serverless (Lambda) | `@sentry/aws-serverless` | 1 per function group | `Sentry.wrapHandler()` + auto-flush |
| Serverless (GCP) | `@sentry/google-cloud-serverless` | 1 per function group | `Sentry.wrapCloudEventFunction()` |
| Event-driven (Kafka/SQS) | `@sentry/node` | 1 per consumer group | `continueTrace()` from message headers |
| Frontend SPA | `@sentry/browser` or `@sentry/react` | 1 frontend project | `browserTracingIntegration()` |
| Mobile (React Native) | `@sentry/react-native` | 1 mobile project | Native crash reporting + JS errors |
| Hybrid | Mix of above | 1 per deployment target | Cross-platform trace correlation |
Install the SDK for your architecture:
```bash
# Monolith / Microservices / Event-driven
npm install @sentry/node @sentry/profiling-node
# Serverless — AWS Lambda
npm install @sentry/aws-serverless
# Serverless — Google Cloud Functions
npm install @sentry/google-cloud-serverless
# Frontend SPA (React)
npm install @sentry/react
# Mobile — React Native
npx @sentry/wizard@latest -i reactNative
```
### Step 2 — Initialize Sentry for Each Architecture Pattern
#### Monolith — Single Project, Module Tags
One DSN, one project. Separate concerns with module tags and team ownership rules.
```typescript
// instrument.mjs — load via: node --import ./instrument.mjs app.js
import * as Sentry from '@sentry/node';
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
release: process.env.APP_VERSION,
tracesSampleRate: 0.1,
initialScope: { tags: { app: 'monolith' } },
});
// Tag errors by module so each team sees only their issues
function captureModuleError(module: string, error: Error) {
Sentry.withScope((scope) => {
scope.setTag('module', module);
scope.setTag('team', getTeamForModule(module));
Sentry.captureException(error);
});
}
// Module-based breadcrumbs for traceability
Sentry.addBreadcrumb({ category: 'auth', message: 'Login attempt', level: 'info' });
captureModuleError('auth', new Error('Token expired'));
// Dashboard ownership: tags.module:auth → #platform-team
```
#### Microservices — Project-per-Service, Distributed Tracing
Each service gets its own Sentry project. A shared config package keeps init consistent.
```typescript
// packages/sentry-config/index.ts — shared across all services
import * as Sentry from '@sentry/node';
export function initServiceSentry(serviceName: string) {
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.NODE_ENV,
release: `${serviceName}@${process.env.APP_VERSION}`,
serverName: serviceName,
tracesSampleRate: 0.1,
sendDefaultPii: false,
initialScope: {
tags: {
service: serviceName,
cluster: process.env.K8S_CLUSTER || 'default',
namespace: process.env.K8S_NAMESPACE || 'default',
},
},
});
}
// Usage: initServiceSentry('api-gateway');
```
HTTP tracing works automatically — SDK v8 propagates `sentry-trace` and `baggage` headers on all outbound HTTP requests. For service mesh (Istio/Linkerd), headers pass through transparently. For non-HTTP transports (gRPC, message queues), see event-driven pattern below and [microservices deep-dive](references/microservices-architecture.md).
#### Serverless — Lambda and Cloud Functions
Serverless SDKs wrap your handler to auto-capture errors and flush events before the runtime freezes.
```typescript
// AWS Lambda — handler.ts
import * as Sentry from '@sentry/aws-serverless';
Sentry.init({
dsn: process.env.SENTRY_DSN,
environment: process.env.STAGE,
tracesSampleRate: 0.1,
});
export const handler = Sentry.wrapHandler(async (event, context) => {
Sentry.setTag('function', context.functionName);
Sentry.setTag('region', process.env.AWS_REGION);
// Track cold starts
const isColdStart = !global.__sentryWarm;
global.__sentryWarm = true;
Sentry.setTag('cold_start', String(isColdStart));
const result = await processRequest(event);
return { statusCode: 200, body: JSON.stringify(result) };
});
// wrapHandler auto-calls flush() — do NOT call it yourself (double-flush causes timeout)
```
```typescript
// Google Cloud Functions — index.ts
import * as Sentry from '@sentry/google-cloud-serverless';
Sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 0.1 });
export const httpHandler = Sentry.wrapHttpFunction(async (req, res) => {
res.json(await processRequest(req.body));
});
export const eventHandler = Sentry.wrapCloudEventFunction(async (event) => {
await processEvent(event.data);
});
```
#### Event-Driven — Kafka, SQS, and Message Queues
Propagate trace context through message headers so consumer spans connect to producer traces.
```typescript
import * as Sentry from '@sentry/node';
// Producer: embed trace context in message headers
async function publishToKafka(topic: string, payload: object) {
const activeSpan = Sentry.getActiveSpan();
const headers: Record<string, string> = {};
if (activeSpan) {
headers['sentry-trace'] = Sentry.spanToTraceHeader(activeSpan);
headers['baggage'] = Sentry.spanToBaggageHeader(activeSpan) || '';
}
await Sentry.startSpan(
{ name: `kafka.produce.${topic}`, op: 'queue.publish' },
() => kafka.send({ topic, messages: [{ value: JSON.stringify(payload), headers }] })
);
}
// Consumer: continue the producer's trace
async function consumeFromKafka(message: KafkaMessage) {
const headers = message.headers || {};
Sentry.continueTrace(
{
sentryTrace: headers['sentry-trace']?.toString(), // Buffer → string
baggage: headers['baggage']?.toString(),
},
() => {
Sentry.startSpan(
{ name: `kafka.consume.${message.topic}`, op: 'queue.process' },
async (span) => {
try {
await processMessage(message);
span.setStatus({ code: 1 });
} catch (error) {
span.setStatus({ code: 2, message: 'consumer_error' });
Sentry.captureException(error);
throw error;
}
}
);
}
);
}
```
For SQS consumers on Lambda, see [event-driven deep-dive](references/event-driven-architecture.md).
#### Frontend SPA — Browser and React
```typescript
imRelated in Web Dev
generating-lwc-components
IncludedLightning Web Components with PICKLES methodology and 165-point scoring. Use this skill when the user creates or edits LWC components, builds wire service patterns, or writes Jest tests for LWC. TRIGGER when: user creates/edits LWC components, touches lwc/**/*.js, .html, .css, .js-meta.xml files, or asks about wire service, SLDS, or Jest LWC tests. DO NOT TRIGGER when: Apex classes (use generating-apex), Aura components, or Visualforce.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Set up queries with useQuery, mutations with useMutation, configure QueryClient caching strategies, implement optimistic updates, and handle infinite scroll with useInfiniteQuery. Use when: setting up data fetching in React projects, migrating from v4 to v5, or fixing object syntax required errors, query callbacks removed issues, cacheTime renamed to gcTime, isPending vs isLoading confusion, keepPreviousData removed problems.
document-processor-api
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
nutrient-document-processing
IncludedProcess documents with Nutrient DWS. Use when the user wants to generate PDFs from HTML or URLs, convert Office/images/PDFs, assemble or split packets, OCR scans, extract text/tables/key-value pairs, redact PII, watermark, sign, fill forms, optimize PDFs, or produce compliance outputs like PDF/A or PDF/UA. Triggers include convert to PDF, merge these PDFs, OCR this scan, extract tables, redact PII, sign this PDF, make this PDF/A, or linearize for web delivery.
tanstack-query
IncludedManage server state in React with TanStack Query v5. Covers useMutationState, simplified optimistic updates, throwOnError, network mode (offline/PWA), and infiniteQueryOptions. Use when setting up data fetching, fixing v4→v5 migration errors (object syntax, gcTime, isPending, keepPreviousData), or debugging SSR/hydration issues with streaming server components.
accelint-nextjs-best-practices
IncludedNext.js performance optimization and best practices. Use when writing Next.js code (App Router or Pages Router); implementing Server Components, Server Actions, or API routes; optimizing RSC serialization, data fetching, or server-side rendering; reviewing Next.js code for performance issues; fixing authentication in Server Actions; or implementing Suspense boundaries, parallel data fetching, or request deduplication.