or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

aws-lambda.mdaws-services.mdcore-sentry.mdgcp-functions.mdindex.md
tile.json

tessl/npm-sentry--serverless

Official Sentry SDK for various serverless solutions including AWS Lambda and Google Cloud Functions

Workspace
tessl
Visibility
Public
Created
Last updated
Describes
npmpkg:npm/@sentry/serverless@7.120.x

To install, run

npx @tessl/cli install tessl/npm-sentry--serverless@7.120.0

index.mddocs/

Sentry Serverless

Sentry Serverless is an official SDK that provides comprehensive error monitoring and performance tracing capabilities specifically designed for serverless environments including AWS Lambda and Google Cloud Functions. It wraps the core @sentry/node SDK with added functionality for serverless platforms, enabling automatic error capture, performance monitoring, and distributed tracing.

Package Information

  • Package Name: @sentry/serverless
  • Package Type: npm
  • Language: TypeScript
  • Installation: npm install @sentry/serverless
  • Note: This package was discontinued in v8.0.0 in favor of dedicated platform-specific SDKs

Core Imports

import * as Sentry from "@sentry/serverless";

For namespace-specific imports:

import { AWSLambda, GCPFunction } from "@sentry/serverless";

For CommonJS:

const Sentry = require("@sentry/serverless");
const { AWSLambda, GCPFunction } = require("@sentry/serverless");

Basic Usage

AWS Lambda

import * as Sentry from "@sentry/serverless";

// Initialize Sentry for AWS Lambda
Sentry.AWSLambda.init({
  dsn: "your-dsn-here",
  tracesSampleRate: 1.0,
});

// Wrap your handler
exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {
  // Your handler logic
  throw new Error("Something went wrong!");
});

Google Cloud Functions

import * as Sentry from "@sentry/serverless";

// Initialize Sentry for GCP Functions
Sentry.GCPFunction.init({
  dsn: "your-dsn-here",
  tracesSampleRate: 1.0,
});

// HTTP Functions
exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
  res.send("Hello World!");
});

// Event Functions
exports.helloEvents = Sentry.GCPFunction.wrapEventFunction((data, context, callback) => {
  callback();
});

Architecture

Sentry Serverless is built around several key architectural components:

  • Platform Namespaces: AWSLambda and GCPFunction namespaces provide platform-specific functionality
  • Core SDK Re-exports: All @sentry/node functionality is directly available
  • Handler Wrappers: Platform-specific wrappers that add serverless context and lifecycle management
  • Automatic Integrations: Built-in integrations for AWS services and Google Cloud services
  • Context Enhancement: Automatic addition of serverless environment metadata
  • Lifecycle Management: Proper event flushing and cleanup for serverless execution models

Capabilities

AWS Lambda Integration

Complete AWS Lambda support with handler wrapping, automatic context enhancement, and AWS services integration.

namespace AWSLambda {
  function init(options?: AWSLambdaOptions): void;
  function wrapHandler<TEvent, TResult>(
    handler: Handler<TEvent, TResult>, 
    wrapOptions?: Partial<AWSLambdaWrapperOptions>
  ): Handler<TEvent, TResult>;
  function getDefaultIntegrations(options: Options): Integration[];
}

interface AWSLambdaOptions extends NodeOptions {
  _invokedByLambdaLayer?: boolean;
}

AWS Lambda Integration

Google Cloud Functions Integration

Support for HTTP functions, event functions, and cloud event functions with automatic tracing and error capture.

namespace GCPFunction {
  function init(options?: NodeOptions): void;
  function wrapHttpFunction(
    fn: HttpFunction, 
    wrapOptions?: Partial<HttpFunctionWrapperOptions>
  ): HttpFunction;
  function wrapEventFunction(
    fn: EventFunction | EventFunctionWithCallback,
    wrapOptions?: Partial<EventFunctionWrapperOptions>
  ): EventFunctionWithCallback;
  function wrapCloudEventFunction(
    fn: CloudEventFunction | CloudEventFunctionWithCallback,
    wrapOptions?: Partial<CloudEventFunctionWrapperOptions>
  ): CloudEventFunctionWithCallback;
  function getDefaultIntegrations(options: Options): Integration[];
}

Google Cloud Functions Integration

Core Sentry Functionality

All core Sentry capabilities for error tracking, performance monitoring, and context management.

// Initialization
function init(options?: NodeOptions): void;

// Error Capture
function captureException(exception: any, scope?: (scope: Scope) => Scope): string;
function captureMessage(message: string, level?: SeverityLevel, scope?: (scope: Scope) => Scope): string;

// Performance Monitoring
function startSpan<T>(context: SpanContext, fn: (span: Span) => T): T;
function startSpanManual(context: SpanContext, fn: (span: Span) => T): T;

// Context Management
function withScope<T>(callback: (scope: Scope) => T): T;
function getCurrentScope(): Scope;

Core Sentry Functionality

AWS Services Integration

Automatic tracking and tracing of AWS SDK service requests with detailed operation context.

function awsServicesIntegration(options?: { optional?: boolean }): Integration;

AWS Services Integration

Types

// AWS Lambda Types
type AsyncHandler<T extends Handler> = (
  event: Parameters<T>[0],
  context: Parameters<T>[1]
) => Promise<NonNullable<Parameters<Parameters<T>[2]>[1]>>;

interface AWSLambdaWrapperOptions {
  flushTimeout: number;
  callbackWaitsForEmptyEventLoop: boolean;
  captureTimeoutWarning: boolean;
  timeoutWarningLimit: number;
  captureAllSettledReasons: boolean;
  startTrace: boolean;
}

// Google Cloud Functions Types
interface HttpFunction {
  (req: Request, res: Response): any;
}

interface EventFunction {
  (data: Record<string, any>, context: Context): any;
}

interface EventFunctionWithCallback {
  (data: Record<string, any>, context: Context, callback: Function): any;
}

interface CloudEventFunction {
  (cloudevent: CloudEventsContext): any;
}

interface CloudEventFunctionWithCallback {
  (cloudevent: CloudEventsContext, callback: Function): any;
}

// Context Types
interface CloudFunctionsContext {
  eventId?: string;
  timestamp?: string;
  eventType?: string;
  resource?: string;
}

interface CloudEventsContext {
  [key: string]: any;
  type?: string;
  specversion?: string;
  source?: string;
  id?: string;
  time?: string;
  schemaurl?: string;
  contenttype?: string;
}

type Context = CloudFunctionsContext | CloudEventsContext;

// GCP Function Wrapper Options
interface GCPWrapperOptions {
  flushTimeout: number;
}

interface HttpFunctionWrapperOptions extends GCPWrapperOptions {
  addRequestDataToEventOptions?: AddRequestDataToEventOptions;
}

type EventFunctionWrapperOptions = GCPWrapperOptions;
type CloudEventFunctionWrapperOptions = GCPWrapperOptions;