Skip to content

Commit

Permalink
ddtrace/tracer: add an alias tag (analytics.event) for setting event …
Browse files Browse the repository at this point in the history
…rate (#415)

This change adds support for a new boolean tag ("analytics.event") to serve as
an alias for setting the event sample rate to 0.0 or 1.0.

For example:

    span.SetTag(ext.AnalyticsEvent, true)  // record this event
    span.SetTag(ext.AnalyticsEvent, false) // don't record this event
  • Loading branch information
gbbr authored Mar 22, 2019
1 parent 5340c95 commit 3ef2dec
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
4 changes: 4 additions & 0 deletions ddtrace/ext/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,4 +63,8 @@ const (
// EventSampleRate specifies the rate at which this span will be sampled
// as an APM event.
EventSampleRate = "_dd1.sr.eausr"

// AnalyticsEvent specifies whether the span should be recorded as a Trace
// Search & Analytics event.
AnalyticsEvent = "analytics.event"
)
14 changes: 13 additions & 1 deletion ddtrace/tracer/span.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,21 @@ func (s *span) SetTag(key string, value interface{}) {
if s.finished {
return
}
if key == ext.Error {
switch key {
case ext.Error:
s.setTagError(value, true)
return
case ext.AnalyticsEvent:
// "analytics.event" is a boolean alias for setting the event sampling
// rate to 0.0 or 1.0
if set, ok := value.(bool); ok {
if set {
s.setTagNumeric(ext.EventSampleRate, 1.0)
} else {
s.setTagNumeric(ext.EventSampleRate, 0.0)
}
return
}
}
if v, ok := value.(string); ok {
s.setTagString(key, v)
Expand Down
6 changes: 6 additions & 0 deletions ddtrace/tracer/span_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,12 @@ func TestSpanSetTag(t *testing.T) {

span.SetTag(ext.SamplingPriority, 2)
assert.Equal(float64(2), span.Metrics[keySamplingPriority])

span.SetTag(ext.AnalyticsEvent, true)
assert.Equal(1.0, span.Metrics[ext.EventSampleRate])

span.SetTag(ext.AnalyticsEvent, false)
assert.Equal(0.0, span.Metrics[ext.EventSampleRate])
}

func TestSpanSetDatadogTags(t *testing.T) {
Expand Down

0 comments on commit 3ef2dec

Please sign in to comment.