Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/sentry-architecture-variants

@0d57af8
Run it yourself

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".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/sentry-architecture-variants

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesevent-driven-architecture.md

≈1.1k tokens on demand. Your agent reads this file only when SKILL.md points to it.

Event-Driven Architecture — Sentry Deep Dive

Kafka — Trace Propagation

Producer

import * as Sentry from '@sentry/node';

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' },
    async () => {
      await kafka.send({
        topic,
        messages: [{ value: JSON.stringify(payload), headers }],
      });
    }
  );
}

Consumer

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;
          }
        }
      );
    }
  );
}

SQS — Trace Propagation

Producer (sending to SQS)

import { SQSClient, SendMessageCommand } from '@aws-sdk/client-sqs';

async function sendToSQS(queueUrl: string, body: object) {
  const activeSpan = Sentry.getActiveSpan();
  const messageAttributes: Record<string, any> = {};

  if (activeSpan) {
    messageAttributes['sentry-trace'] = {
      DataType: 'String',
      StringValue: Sentry.spanToTraceHeader(activeSpan),
    };
    messageAttributes['baggage'] = {
      DataType: 'String',
      StringValue: Sentry.spanToBaggageHeader(activeSpan) || '',
    };
  }

  await sqs.send(new SendMessageCommand({
    QueueUrl: queueUrl,
    MessageBody: JSON.stringify(body),
    MessageAttributes: messageAttributes,
  }));
}

Consumer (Lambda SQS trigger)

import * as Sentry from '@sentry/aws-serverless';

export const handler = Sentry.wrapHandler(async (event) => {
  for (const record of event.Records) {
    const attrs = record.messageAttributes;
    const sentryTrace = attrs?.['sentry-trace']?.stringValue;
    const baggage = attrs?.['baggage']?.stringValue;

    await Sentry.continueTrace({ sentryTrace, baggage }, () => {
      return Sentry.startSpan(
        { name: 'sqs.process', op: 'queue.process' },
        () => processRecord(record)
      );
    });
  }
});

Dead Letter Queue Handling

// DLQ consumer should capture the original error context
async function processDLQ(message: DLQMessage) {
  Sentry.withScope((scope) => {
    scope.setTag('queue', 'dlq');
    scope.setTag('original_queue', message.originalQueue);
    scope.setTag('retry_count', String(message.retryCount));
    scope.setContext('original_error', {
      error: message.failureReason,
      timestamp: message.firstFailureAt,
    });

    Sentry.captureMessage(
      `DLQ: ${message.failureReason}`,
      message.retryCount > 5 ? 'error' : 'warning'
    );
  });
}

Long-Running Consumer Flush

For non-serverless consumers (ECS, K8s pods), events buffer in memory. Add periodic flush:

// Flush every 30 seconds to prevent event loss on crash
setInterval(() => Sentry.flush(2000), 30_000);

// Also flush on graceful shutdown
process.on('SIGTERM', async () => {
  await Sentry.flush(5000);
  process.exit(0);
});

Common Gotcha: Buffer vs String Headers

Kafka headers are Buffer objects, not strings. Always call .toString():

// WRONG — headers are Buffers
const sentryTrace = headers['sentry-trace'];

// CORRECT — convert to string
const sentryTrace = headers['sentry-trace']?.toString();

Tons of Skills by Intent Solutions | jeremylongshore.com

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    This skill provides architectural guidance and code snippets for integrating Sentry error tracking and performance monitoring into various application types. No security issues or malicious patterns were detected.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 3 months ago
What it can do
Reads files Edits files Runs commands
version
1.51.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 7 allowed tools
ReadWriteEditGrepGlobBash(node:*)Bash(npx:*)
Other metadata
tags
[
  "saas",
  "sentry",
  "serverless",
  "microservices",
  "architecture",
  "distributed-tracing",
  "lambda",
  "spa",
  "mobile"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/sentry-architecture-variants