-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Philipp Jardas
committed
Sep 22, 2022
1 parent
efc055f
commit b5ea920
Showing
7 changed files
with
272 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"easy-apigateway": minor | ||
--- | ||
|
||
Add support for Sentry |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { AWSLambda, type User } from "@sentry/serverless"; | ||
import type { Handler } from "aws-lambda"; | ||
|
||
export type SentryOptions = { | ||
environment: string; | ||
dsn: string; | ||
enabled: boolean; | ||
tracesSampleRate?: number; | ||
}; | ||
|
||
export type SentryWrapper = <TEvent, TResult>( | ||
handler: Handler<TEvent, TResult>, | ||
wrapOptions?: Partial<AWSLambda.WrapperOptions> | ||
) => Handler<TEvent, TResult>; | ||
|
||
export function createSentryWrapper(options?: SentryOptions): SentryWrapper { | ||
console.log("Sentry DSN:", options?.dsn); | ||
if (!options?.dsn) return (handler) => handler; | ||
|
||
AWSLambda.init(options); | ||
|
||
return (handler, wrapOptions) => AWSLambda.wrapHandler(handler, wrapOptions); | ||
} | ||
|
||
export function setSentryUser(user?: User): void { | ||
AWSLambda.setUser(user ?? null); | ||
} | ||
|
||
export function captureErrorWithSentry(err: unknown): void { | ||
AWSLambda.captureException(err); | ||
} |
Oops, something went wrong.