Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion client.go
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,6 @@ func (client *Client) setupTelemetryProcessor() {

func (client *Client) setupIntegrations() {
integrations := []Integration{
new(contextifyFramesIntegration),
new(environmentIntegration),
new(modulesIntegration),
new(ignoreErrorsIntegration),
Expand Down
1 change: 0 additions & 1 deletion client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1130,7 +1130,6 @@ func TestTelemetryEnvelopeCarriesIntegrations(t *testing.T) {

assert.Equal(t, sdkIdentifier, header.Sdk.Name)
assert.Contains(t, header.Sdk.Integrations, "CustomRegressionIntegration")
assert.Contains(t, header.Sdk.Integrations, "ContextifyFrames")
}

func TestClient_SetupTelemetryBuffer_NoDSN(t *testing.T) {
Expand Down
115 changes: 0 additions & 115 deletions integrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,121 +214,6 @@ func (iei *ignoreTransactionsIntegration) processor(event *Event, _ *EventHint)
return event
}

// ================================
// Contextify Frames Integration
// ================================

type contextifyFramesIntegration struct {
sr sourceReader
contextLines int
cachedLocations sync.Map
}

func (cfi *contextifyFramesIntegration) Name() string {
return "ContextifyFrames"
}

func (cfi *contextifyFramesIntegration) SetupOnce(client *Client) {
cfi.sr = newSourceReader()
cfi.contextLines = 5

client.AddEventProcessor(cfi.processor)
}

func (cfi *contextifyFramesIntegration) processor(event *Event, _ *EventHint) *Event {
// Range over all exceptions
for _, ex := range event.Exception {
// If it has no stacktrace, just bail out
if ex.Stacktrace == nil {
continue
}

// If it does, it should have frames, so try to contextify them
ex.Stacktrace.Frames = cfi.contextify(ex.Stacktrace.Frames)
}

// Range over all threads
for _, th := range event.Threads {
// If it has no stacktrace, just bail out
if th.Stacktrace == nil {
continue
}

// If it does, it should have frames, so try to contextify them
th.Stacktrace.Frames = cfi.contextify(th.Stacktrace.Frames)
}

return event
}

func (cfi *contextifyFramesIntegration) contextify(frames []Frame) []Frame {
contextifiedFrames := make([]Frame, 0, len(frames))

for _, frame := range frames {
if !frame.InApp {
contextifiedFrames = append(contextifiedFrames, frame)
continue
}

var path string

if cachedPath, ok := cfi.cachedLocations.Load(frame.AbsPath); ok {
if p, ok := cachedPath.(string); ok {
path = p
}
} else {
// Optimize for happy path here
if fileExists(frame.AbsPath) {
path = frame.AbsPath
} else {
path = cfi.findNearbySourceCodeLocation(frame.AbsPath)
}
}

if path == "" {
contextifiedFrames = append(contextifiedFrames, frame)
continue
}

lines, contextLine := cfi.sr.readContextLines(path, frame.Lineno, cfi.contextLines)
contextifiedFrames = append(contextifiedFrames, cfi.addContextLinesToFrame(frame, lines, contextLine))
}

return contextifiedFrames
}

func (cfi *contextifyFramesIntegration) findNearbySourceCodeLocation(originalPath string) string {
trimmedPath := strings.TrimPrefix(originalPath, "/")
components := strings.Split(trimmedPath, "/")

for len(components) > 0 {
components = components[1:]
possibleLocation := strings.Join(components, "/")

if fileExists(possibleLocation) {
cfi.cachedLocations.Store(originalPath, possibleLocation)
return possibleLocation
}
}

cfi.cachedLocations.Store(originalPath, "")
return ""
}

func (cfi *contextifyFramesIntegration) addContextLinesToFrame(frame Frame, lines [][]byte, contextLine int) Frame {
for i, line := range lines {
switch {
case i < contextLine:
frame.PreContext = append(frame.PreContext, string(line))
case i == contextLine:
frame.ContextLine = string(line)
default:
frame.PostContext = append(frame.PostContext, string(line))
}
}
return frame
}

// ================================
// Global Tags Integration
// ================================
Expand Down
71 changes: 0 additions & 71 deletions integrations_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package sentry
import (
"encoding/json"
"os"
"path/filepath"
"regexp"
"runtime/debug"
"testing"
Expand Down Expand Up @@ -227,76 +226,6 @@ func TestIgnoreTransactionsIntegration(t *testing.T) {
}
}

func TestContextifyFrames(t *testing.T) {
cfi := contextifyFramesIntegration{
sr: newSourceReader(),
contextLines: 5,
}

filename := "errors_test.go"
abspath, err := filepath.Abs("errors_test.go")
if err != nil {
t.Fatal(err)
}

frames := cfi.contextify([]Frame{{
Function: "Trace",
Module: "github.com/getsentry/sentry-go",
Filename: filename,
AbsPath: abspath,
Lineno: 12,
InApp: true,
}})
if len(frames) != 1 {
t.Fatalf("got %d frames, want 1", len(frames))
}
frame := frames[0]

assertEqual(t, frame.PreContext, []string{
")",
"",
"// NOTE: if you modify this file, you are also responsible for updating LoC position in Stacktrace tests",
"",
"func Trace() *Stacktrace {",
})
assertEqual(t, frame.ContextLine, "\treturn NewStacktrace()")
assertEqual(t, frame.PostContext, []string{
"}",
"",
"func RedPkgErrorsRanger() error {",
"\treturn BluePkgErrorsRanger()",
"}",
})
}

func TestContextifyFramesNonexistingFilesShouldNotDropFrames(t *testing.T) {
cfi := contextifyFramesIntegration{
sr: newSourceReader(),
contextLines: 5,
}

frames := []Frame{{
InApp: true,
Function: "fnName",
Module: "same",
Filename: "wat.go",
AbsPath: "this/doesnt/exist/wat.go",
Lineno: 1,
Colno: 2,
}, {
InApp: false,
Function: "fnNameFoo",
Module: "sameFoo",
Filename: "foo.go",
AbsPath: "this/doesnt/exist/foo.go",
Lineno: 3,
Colno: 5,
}}

contextifiedFrames := cfi.contextify(frames)
assertEqual(t, len(contextifiedFrames), len(frames))
}

func TestExtractModules(t *testing.T) {
tests := []struct {
name string
Expand Down
70 changes: 0 additions & 70 deletions sourcereader.go

This file was deleted.

Loading
Loading