Skip to content
This repository was archived by the owner on Aug 30, 2023. It is now read-only.

Add interface for custom source code loaders #207

Merged
merged 2 commits into from
Oct 18, 2018

Conversation

VojtechVitek
Copy link
Contributor

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.

Copy link
Member

@dcramer dcramer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Been a while since I've touched Go - wouldn't it make sense to be able to inject a SourceCodeLoader as part of configuration as well? That may not be an important enough use case, so I'll go ahead and merge this for now.

@dcramer
Copy link
Member

dcramer commented Oct 18, 2018

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

@dcramer dcramer merged commit 6a5e526 into getsentry:master Oct 18, 2018
sjung-stripe added a commit to stripe-archive/raven-go that referenced this pull request Nov 28, 2018
dcramer pushed a commit that referenced this pull request Nov 28, 2018
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants