Skip to content

Commit 14ddd27

Browse files
authored
allow users to record stacktraces in span events (#38)
1 parent 63183b7 commit 14ddd27

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

tracing/option.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,10 @@ func WithoutMetrics() Option {
4949
p.excludeMetrics = true
5050
}
5151
}
52+
53+
// WithRecordStackTrace includes a stack trace inside exception events
54+
func WithRecordStackTrace() Option {
55+
return func(p *otelPlugin) {
56+
p.recordStackTraceInSpan = true
57+
}
58+
}

tracing/tracing.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ var (
2828
)
2929

3030
type otelPlugin struct {
31-
provider trace.TracerProvider
32-
tracer trace.Tracer
33-
attrs []attribute.KeyValue
34-
excludeQueryVars bool
35-
excludeMetrics bool
36-
queryFormatter func(query string) string
31+
provider trace.TracerProvider
32+
tracer trace.Tracer
33+
attrs []attribute.KeyValue
34+
excludeQueryVars bool
35+
excludeMetrics bool
36+
recordStackTraceInSpan bool
37+
queryFormatter func(query string) string
3738
}
3839

3940
func NewPlugin(opts ...Option) gorm.Plugin {
@@ -115,7 +116,7 @@ func (p *otelPlugin) after() gormHookFunc {
115116
if !span.IsRecording() {
116117
return
117118
}
118-
defer span.End()
119+
defer span.End(trace.WithStackTrace(p.recordStackTraceInSpan))
119120

120121
attrs := make([]attribute.KeyValue, 0, len(p.attrs)+4)
121122
attrs = append(attrs, p.attrs...)

0 commit comments

Comments
 (0)