Add @sentry/serverless as a dependency:
npm install --save @sentry/aws-serverless
Then set up the AWS Lambda integration:
const Sentry = require("@sentry/aws-serverless");
Sentry.init({
dsn: 'https://<key>@sentry.io/<project>',
tracesSampleRate: 1.0,
});
exports.handler = Sentry.wrapHandler(async (event, context) => {
// Your handler code
});
Install our Python SDK using pip:
pip install --upgrade sentry-sdk
Then use the AWS Lambda integration for the Python SDK like this:
import sentry_sdk
sentry_sdk.init(
dsn="https://<key>@sentry.io/<project>",
integrations=[AwsLambdaIntegration()],
traces_sample_rate=1.0, # adjust the sample rate in production as needed
)
def my_function(event, context):
# ...
Add @sentry/serverless as a dependency to package.json:
"@sentry/serverless": "*"
Then set up Sentry error logging for a GCP Cloud Function:
const Sentry = require("@sentry/serverless");
Sentry.GCPFunction.init({
dsn: "https://<key>@sentry.io/<project>",
tracesSampleRate: 1.0,
});
exports.helloHttp = Sentry.GCPFunction.wrapHttpFunction((req, res) => {
throw new Error('oh, hello there!');
});
Add the Sentry SDK to your requirements.txt:
Then use the GCP Functions integration for the Python SDK like this:
import sentry_sdk
from sentry_sdk.integrations.gcp import GcpIntegration
sentry_sdk.init(
dsn="https://<key>@sentry.io/<project>",
integrations=[GcpIntegration()],
traces_sample_rate=1.0, # adjust the sample rate in production as needed
)
def http_function_entrypoint(request):
# ...
Add @sentry/node as a dependency:
npm install --save @sentry/node
Then set up Sentry error logging for an Azure Function:
"use strict";
const Sentry = require("@sentry/node");
Sentry.init({
dsn: "https://<key>@sentry.io/<project>",
});
module.exports = async function(context, req) {
try {
await notExistFunction();
} catch (e) {
Sentry.captureException(e);
await Sentry.flush(2000);
}
context.res = {
status: 200,
body: "Hello from Azure Cloud Function!",
};
};
Add @sentry/cloudflare as a dependency:
npm install --save @sentry/cloudflare
Configure the nodejs_compat compatibility flag in your wrangler.json:
{
"compatibility_flags": [
"nodejs_compat"
],
"compatibility_date": "2024-01-01"
}
Then add the Sentry middleware to your Cloudflare Pages functions:
import * as Sentry from "@sentry/cloudflare";
export const onRequest = [
// Make sure Sentry is the first middleware
Sentry.sentryPagesPlugin((context) => ({
dsn: 'https://<key>@sentry.io/<project>',
tracesSampleRate: 1.0,
})),
// Add more middlewares here
];
Add @sentry/cloudflare as a dependency:
npm install --save @sentry/cloudflare
Configure the nodejs_compat compatibility flag in your wrangler.json:
{
"compatibility_flags": [
"nodejs_compat"
],
"compatibility_date": "2024-01-01"
}
Then wrap your handler with the withSentry function:
import * as Sentry from "@sentry/cloudflare";
export default Sentry.withSentry(
(env) => ({
dsn: 'https://<key>@sentry.io/<project>',
tracesSampleRate: 1.0,
enableLogs: true,
}),
{
async fetch(request, env, ctx) {
return new Response('Hello World!');
},
}
);
Add @sentry/node as a dependency:
npm install --save @sentry/node
Create an initialization file (e.g., init.ts) that runs before your functions:
import * as Sentry from '@sentry/node';
Sentry.init({
dsn: 'https://<key>@sentry.io/<project>',
tracesSampleRate: 1.0,
});
Import the initialization file at the top of your functions entry point:
import './init'; // Import Sentry initialization first
import { onRequest } from 'firebase-functions/https';
import { onDocumentCreated } from 'firebase-functions/firestore';
import * as admin from 'firebase-admin';
admin.initializeApp();
const db = admin.firestore();
// HTTP function - automatically instrumented
export const helloWorld = onRequest(async (request, response) => {
response.send('Hello from Firebase!');
});
// Firestore trigger - automatically instrumented
export const onUserCreated = onDocumentCreated('users/{userId}', async (event) => {
const userId = event.params.userId;
// Your logic here
});