Serverless

sentry-go SDK comes with the support for serverless solutions out of the box. However, to get the source contexts right, you need to bundle your source code with the binary itself.

For example, when using AWS Lambda and given this tree structure:

Copied
.
├── bin
│   └── upload-image
│   └── process-image
│   └── create-thumbnails
├── functions
│   └── upload-image
│       └── main.go
│   └── process-image
│       └── main.go
│   └── create-thumbnails
│       └── main.go
├── helper
│   ├── foo.go
│   └── bar.go
├── util
│   ├── baz.go
│   └── qux.go

You can build one of the binaries and bundle them with the necessary source files with this command:

Copied
GOOS=linux go build -o bin/upload-image functions/upload-image/main.go && zip -r handler.zip bin/upload-image functions/upload-image/ helper/ util/

The only requirement is that you locate the source code on the deployed machine. Everything else should be done automatically by the SDK.

Most (if not all) serverless solutions won't wait for network responses before closing the process. Because of that, we need to make sure that the event is delivered to Sentry's servers.

It can be achieved twofold, using the sentry.Flush method or by swapping the transport to HTTPSyncTransport.

Help improve this content
Our documentation is open source and available on GitHub. Your contributions are welcome, whether fixing a typo (drat!) or suggesting an update ("yeah, this would be better").