getsentry / raven-go

Sentry client in Go
https://sentry.io
BSD 3-Clause "New" or "Revised" License
561 stars 148 forks source link

Add interface for custom source code loaders #207

Closed VojtechVitek closed 6 years ago

VojtechVitek commented 6 years ago

Rationale

We'd like to send source code context into Sentry alerts along with stacktraces. This works on localhost or on machines that have the source code available on the file system.

But we don't want to ship the source code of our repository in plain text as part of the Docker image because of disk space and security reasons.

However, we still want to receive source code context in our production Sentry alerts.

Proposal

Let raven-go users define their own "storage" of the source code files.

Change the fileContext(filename string, line, context int) ([][]byte, int) stacktrace.go function to an implementation of a new interface:

type SourceCodeLoader interface {
    Load(filename string, line, context int) ([][]byte, int)
}

Example of custom source code loader

customLoader := staticfiles.SentrySourceCodeLoader()
raven.SetSourceCodeLoader(customLoader)

We plan to embed the source code into the binary via https://github.com/shurcooL/vfsgen and implement the interface on top of http.FileSystem.

The custom loader can be built on anything that can provide source code, either if it's static files built into binaries (like vfsgen, packer etc.), or an implementation that pulls the source code directly from Github.

dcramer commented 6 years ago

Actually, ignore that comment, I see the setter now. Lack of sleep :)