Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ddtrace/tracer: add WithDebugStack StartOption to configure stack traces. #739

Merged
merged 2 commits into from
Sep 22, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,10 @@ type config struct {
// tickChan specifies a channel which will receive the time every time the tracer must flush.
// It defaults to time.Ticker; replaced in tests.
tickChan <-chan time.Time

// noDebugStack disables the collection of debug stack traces globally. No traces reporting
// errors will record a stack trace when this option is set.
noDebugStack bool
}

// StartOption represents a function that can be provided as a parameter to Start.
Expand Down Expand Up @@ -249,6 +253,15 @@ func WithPrioritySampling() StartOption {
}
}

// WithDebugStack can be used to globally enable or disable the collection of stack traces when
// spans finish with errors. It is enabled by default. This is a global version of the NoDebugStack
// FinishOption.
func WithDebugStack(enabled bool) StartOption {
return func(c *config) {
c.noDebugStack = !enabled
}
}

// WithDebugMode enables debug mode on the tracer, resulting in more verbose logging.
func WithDebugMode(enabled bool) StartOption {
return func(c *config) {
Expand Down
7 changes: 5 additions & 2 deletions ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type span struct {
TraceID uint64 `msg:"trace_id"` // identifier of the root span
ParentID uint64 `msg:"parent_id"` // identifier of the span's direct parent
Error int32 `msg:"error"` // error status of the span; 0 means no errors
errCfg errorConfig `msg:"-"` // configuration for errors tracing
gbbr marked this conversation as resolved.
Show resolved Hide resolved

finished bool `msg:"-"` // true if the span has been submitted to a tracer.
context *spanContext `msg:"-"` // span propagation context
Expand Down Expand Up @@ -102,7 +103,7 @@ func (s *span) SetTag(key string, value interface{}) {
}
switch key {
case ext.Error:
s.setTagError(value, &errorConfig{})
s.setTagError(value, &s.errCfg)
return
}
if v, ok := value.(bool); ok {
Expand Down Expand Up @@ -260,7 +261,9 @@ func (s *span) setMetric(key string, v float64) {
func (s *span) Finish(opts ...ddtrace.FinishOption) {
t := now()
if len(opts) > 0 {
var cfg ddtrace.FinishConfig
cfg := ddtrace.FinishConfig{
NoDebugStack: s.errCfg.noDebugStack,
}
for _, fn := range opts {
fn(&cfg)
}
Expand Down
1 change: 1 addition & 0 deletions ddtrace/tracer/tracer.go
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ func (t *tracer) StartSpan(operationName string, options ...ddtrace.StartSpanOpt
TraceID: id,
Start: startTime,
taskEnd: startExecutionTracerTask(operationName),
errCfg: errorConfig{noDebugStack: t.config.noDebugStack},
}
if context != nil {
// this is a child span
Expand Down
16 changes: 15 additions & 1 deletion ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ package tracer

import (
"context"
"errors"
"io"
"io/ioutil"
"net/http"
Expand Down Expand Up @@ -59,7 +60,7 @@ loop:
}
}

// TestTracerFrenetic does frenetic testing in a scenario where the tracer is started
// TestTracerCleanStop does frenetic testing in a scenario where the tracer is started
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Unrelated doc change

// and stopped in parallel with spans being created.
func TestTracerCleanStop(t *testing.T) {
if testing.Short() {
Expand Down Expand Up @@ -442,6 +443,19 @@ func TestTracerSpanGlobalTags(t *testing.T) {
assert.Equal("value", child.Meta["key"])
}

func TestTracerNoDebugStack(t *testing.T) {
assert := assert.New(t)
tracer := newTracer(WithDebugStack(false))
s := tracer.StartSpan("web.request").(*span)
err := errors.New("test error")
s.Finish(WithError(err))

assert.Equal(int32(1), s.Error)
assert.Equal("test error", s.Meta[ext.ErrorMsg])
assert.Equal("*errors.errorString", s.Meta[ext.ErrorType])
assert.Empty(s.Meta[ext.ErrorStack])
}

func TestNewSpan(t *testing.T) {
assert := assert.New(t)

Expand Down