Skip to main content
The Sentry Google Cloud Functions SDK provides error monitoring and performance tracking for serverless functions running on Google Cloud Platform with automatic function wrapping.

Installation

Basic Setup

Initialize Sentry

Initialize Sentry at the top of your function file:

Function Types

HTTP Functions

Wrap HTTP functions with wrapHttpFunction:

Background Functions

Wrap background (event-driven) functions with wrapEventFunction:

CloudEvents

Wrap CloudEvent functions with wrapCloudEventFunction:

Error Handling

HTTP Function Errors

Background Function Errors

Performance Monitoring

Custom Spans

External API Calls

Context and Tags

Function Context

User Identification

Firebase Integration

Firestore Triggers

Pub/Sub Triggers

Environment Variables

Configure using environment variables:
Or in your deployment configuration:

Cloud Run

For Cloud Run deployments:

Terraform Deployment

Configure with Terraform:

Best Practices

Wrap Functions

Always wrap your functions with appropriate Sentry wrapper.

Set Context

Add function and event context for better debugging.

Handle Retries

Consider retry logic when reporting errors in event functions.

Environment Config

Use environment variables for configuration.

Troubleshooting

Ensure:
  1. Function is wrapped with appropriate wrapper
  2. SENTRY_DSN is configured
  3. Function has internet access
  4. Errors are being thrown or captured
Consider:
  1. Increase function timeout
  2. Use async error reporting
  3. Ensure Sentry.flush() is called before exit

Next Steps

Firestore

Track Firestore operations

Pub/Sub

Monitor message processing

Cloud Run

Deploy containerized applications

Firebase

Integrate with Firebase services