getsentry/sentry-go

Capture stacktrace for out-of-band errors

miparnisari opened this issue · 3 comments

What is the proper way of capturing the stacktrace of an error when the capturing itself is done "out-of-band" (not sure if this is the proper way of calling it)? For example, in a logging middleware that runs at the end of every request? In my current setup I have AttachStacktrace = true and this code

func (c *SentryClient) LogException(ctx context.Context, err error, operation string, extras map[string]interface{}) {
	c.hub.ConfigureScope(func(scope *sentry.Scope) {
		scope.SetExtras(extras)
		scope.SetUser(sentry.User{ID: "user-id-here"})
		transaction := sentry.TransactionFromContext(ctx)
		if transaction != nil {
			transaction.Name = operation
		}
	})
	c.hub.CaptureException(err)
}

But this shows the stacktrace as follows, which is not what I want...

/instrumentation/exceptions.go in (*SentryClient).LogException at line 58
In App
/middleware/logging.go in (*InstrumentationInterceptor).logRPC at line 212
In App
/middleware/logging.go in runServer.(*InstrumentationInterceptor).NewUnaryInstrumentationInterceptor.func14 at line 74

This is the code that generates the stack trace https://github.com/getsentry/sentry-go/blob/master/stacktrace.go#L74-L101
Are you using any of the error packages mentioned?

This issue has gone three weeks without activity. In another week, I will close it.

But! If you comment or otherwise update it, I will reset the clock, and if you label it Status: Backlog or Status: In Progress, I will leave it alone ... forever!


"A weed is but an unloved flower." ― Ella Wheeler Wilcox 🥀