or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

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

0

# Sentry Serverless

1

2

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.

3

4

## Package Information

5

6

- **Package Name**: @sentry/serverless

7

- **Package Type**: npm

8

- **Language**: TypeScript

9

- **Installation**: `npm install @sentry/serverless`

10

- **Note**: This package was discontinued in v8.0.0 in favor of dedicated platform-specific SDKs

11

12

## Core Imports

13

14

```typescript

15

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

16

```

17

18

For namespace-specific imports:

19

20

```typescript

21

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

22

```

23

24

For CommonJS:

25

26

```javascript

27

const Sentry = require("@sentry/serverless");

28

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

29

```

30

31

## Basic Usage

32

33

### AWS Lambda

34

35

```typescript

36

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

37

38

// Initialize Sentry for AWS Lambda

39

Sentry.AWSLambda.init({

40

dsn: "your-dsn-here",

41

tracesSampleRate: 1.0,

42

});

43

44

// Wrap your handler

45

exports.handler = Sentry.AWSLambda.wrapHandler(async (event, context) => {

46

// Your handler logic

47

throw new Error("Something went wrong!");

48

});

49

```

50

51

### Google Cloud Functions

52

53

```typescript

54

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

55

56

// Initialize Sentry for GCP Functions

57

Sentry.GCPFunction.init({

58

dsn: "your-dsn-here",

59

tracesSampleRate: 1.0,

60

});

61

62

// HTTP Functions

63

exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {

64

res.send("Hello World!");

65

});

66

67

// Event Functions

68

exports.helloEvents = Sentry.GCPFunction.wrapEventFunction((data, context, callback) => {

69

callback();

70

});

71

```

72

73

## Architecture

74

75

Sentry Serverless is built around several key architectural components:

76

77

- **Platform Namespaces**: `AWSLambda` and `GCPFunction` namespaces provide platform-specific functionality

78

- **Core SDK Re-exports**: All @sentry/node functionality is directly available

79

- **Handler Wrappers**: Platform-specific wrappers that add serverless context and lifecycle management

80

- **Automatic Integrations**: Built-in integrations for AWS services and Google Cloud services

81

- **Context Enhancement**: Automatic addition of serverless environment metadata

82

- **Lifecycle Management**: Proper event flushing and cleanup for serverless execution models

83

84

## Capabilities

85

86

### AWS Lambda Integration

87

88

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

89

90

```typescript { .api }

91

namespace AWSLambda {

92

function init(options?: AWSLambdaOptions): void;

93

function wrapHandler<TEvent, TResult>(

94

handler: Handler<TEvent, TResult>,

95

wrapOptions?: Partial<AWSLambdaWrapperOptions>

96

): Handler<TEvent, TResult>;

97

function getDefaultIntegrations(options: Options): Integration[];

98

}

99

100

interface AWSLambdaOptions extends NodeOptions {

101

_invokedByLambdaLayer?: boolean;

102

}

103

```

104

105

[AWS Lambda Integration](./aws-lambda.md)

106

107

### Google Cloud Functions Integration

108

109

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

110

111

```typescript { .api }

112

namespace GCPFunction {

113

function init(options?: NodeOptions): void;

114

function wrapHttpFunction(

115

fn: HttpFunction,

116

wrapOptions?: Partial<HttpFunctionWrapperOptions>

117

): HttpFunction;

118

function wrapEventFunction(

119

fn: EventFunction | EventFunctionWithCallback,

120

wrapOptions?: Partial<EventFunctionWrapperOptions>

121

): EventFunctionWithCallback;

122

function wrapCloudEventFunction(

123

fn: CloudEventFunction | CloudEventFunctionWithCallback,

124

wrapOptions?: Partial<CloudEventFunctionWrapperOptions>

125

): CloudEventFunctionWithCallback;

126

function getDefaultIntegrations(options: Options): Integration[];

127

}

128

```

129

130

[Google Cloud Functions Integration](./gcp-functions.md)

131

132

### Core Sentry Functionality

133

134

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

135

136

```typescript { .api }

137

// Initialization

138

function init(options?: NodeOptions): void;

139

140

// Error Capture

141

function captureException(exception: any, scope?: (scope: Scope) => Scope): string;

142

function captureMessage(message: string, level?: SeverityLevel, scope?: (scope: Scope) => Scope): string;

143

144

// Performance Monitoring

145

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

146

function startSpanManual(context: SpanContext, fn: (span: Span) => T): T;

147

148

// Context Management

149

function withScope<T>(callback: (scope: Scope) => T): T;

150

function getCurrentScope(): Scope;

151

```

152

153

[Core Sentry Functionality](./core-sentry.md)

154

155

### AWS Services Integration

156

157

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

158

159

```typescript { .api }

160

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

161

```

162

163

[AWS Services Integration](./aws-services.md)

164

165

## Types

166

167

```typescript { .api }

168

// AWS Lambda Types

169

type AsyncHandler<T extends Handler> = (

170

event: Parameters<T>[0],

171

context: Parameters<T>[1]

172

) => Promise<NonNullable<Parameters<Parameters<T>[2]>[1]>>;

173

174

interface AWSLambdaWrapperOptions {

175

flushTimeout: number;

176

callbackWaitsForEmptyEventLoop: boolean;

177

captureTimeoutWarning: boolean;

178

timeoutWarningLimit: number;

179

captureAllSettledReasons: boolean;

180

startTrace: boolean;

181

}

182

183

// Google Cloud Functions Types

184

interface HttpFunction {

185

(req: Request, res: Response): any;

186

}

187

188

interface EventFunction {

189

(data: Record<string, any>, context: Context): any;

190

}

191

192

interface EventFunctionWithCallback {

193

(data: Record<string, any>, context: Context, callback: Function): any;

194

}

195

196

interface CloudEventFunction {

197

(cloudevent: CloudEventsContext): any;

198

}

199

200

interface CloudEventFunctionWithCallback {

201

(cloudevent: CloudEventsContext, callback: Function): any;

202

}

203

204

// Context Types

205

interface CloudFunctionsContext {

206

eventId?: string;

207

timestamp?: string;

208

eventType?: string;

209

resource?: string;

210

}

211

212

interface CloudEventsContext {

213

[key: string]: any;

214

type?: string;

215

specversion?: string;

216

source?: string;

217

id?: string;

218

time?: string;

219

schemaurl?: string;

220

contenttype?: string;

221

}

222

223

type Context = CloudFunctionsContext | CloudEventsContext;

224

225

// GCP Function Wrapper Options

226

interface GCPWrapperOptions {

227

flushTimeout: number;

228

}

229

230

interface HttpFunctionWrapperOptions extends GCPWrapperOptions {

231

addRequestDataToEventOptions?: AddRequestDataToEventOptions;

232

}

233

234

type EventFunctionWrapperOptions = GCPWrapperOptions;

235

type CloudEventFunctionWrapperOptions = GCPWrapperOptions;

236

```