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

all: add runtime-id to profiler and tracer global tags. #692

Merged
merged 6 commits into from
Jul 9, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
3 changes: 3 additions & 0 deletions ddtrace/ext/tags.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,4 +82,7 @@ const (
// ManualDrop is a tag which specifies that the trace to which this span
// belongs to should be dropped when set to true.
ManualDrop = "manual.drop"

// RuntimeID is a tag that contains a unique id for this process.
RuntimeID = "runtime-id"
)
1 change: 1 addition & 0 deletions ddtrace/tracer/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func newConfig(opts ...StartOption) *config {
for _, fn := range opts {
fn(c)
}
WithGlobalTag(ext.RuntimeID, globalconfig.GetRuntimeID())(c)
if c.env == "" {
if v, ok := c.globalTags["env"]; ok {
if e, ok := v.(string); ok {
Expand Down
2 changes: 2 additions & 0 deletions ddtrace/tracer/tracer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/ext"
"gopkg.in/DataDog/dd-trace-go.v1/ddtrace/internal"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -190,6 +191,7 @@ func TestTracerStartSpan(t *testing.T) {
// A span is not measured unless made so specifically
_, ok := span.Meta[keyMeasured]
assert.False(ok)
assert.Equal(globalconfig.GetRuntimeID(), span.Meta[ext.RuntimeID])
knusbaum marked this conversation as resolved.
Show resolved Hide resolved
})

t.Run("priority", func(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions internal/globalconfig/globalconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,20 @@ package globalconfig
import (
"math"
"sync"

"github.com/google/uuid"
)

var cfg = &config{
analyticsRate: math.NaN(),
runtimeID: uuid.New().String(),
}

type config struct {
mu sync.RWMutex
analyticsRate float64
serviceName string
runtimeID string
}

// AnalyticsRate returns the sampling rate at which events should be marked. It uses
Expand Down Expand Up @@ -51,3 +55,10 @@ func SetServiceName(name string) {
defer cfg.mu.Unlock()
cfg.serviceName = name
}

// GetRuntimeID returns this process's unique runtime id.
func GetRuntimeID() string {
knusbaum marked this conversation as resolved.
Show resolved Hide resolved
cfg.mu.RLock()
defer cfg.mu.RUnlock()
return cfg.runtimeID
}
2 changes: 2 additions & 0 deletions profiler/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (
"strings"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/log"
"gopkg.in/DataDog/dd-trace-go.v1/internal/version"

Expand Down Expand Up @@ -131,6 +132,7 @@ func defaultConfig() *config {
"runtime_compiler:"+runtime.Compiler,
"runtime_arch:"+runtime.GOARCH,
"runtime_os:"+runtime.GOOS,
"runtime-id:"+globalconfig.GetRuntimeID(),
)(&c)
// not for public use
if v := os.Getenv("DD_PROFILING_URL"); v != "" {
Expand Down
2 changes: 2 additions & 0 deletions profiler/options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (

"github.com/DataDog/datadog-go/statsd"
"github.com/stretchr/testify/assert"
"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
)

func TestOptions(t *testing.T) {
Expand Down Expand Up @@ -242,6 +243,7 @@ func TestDefaultConfig(t *testing.T) {
assert.Equal(DefaultDuration, cfg.cpuDuration)
assert.Equal(DefaultMutexFraction, cfg.mutexFraction)
assert.Equal(DefaultBlockRate, cfg.blockRate)
assert.Contains(cfg.tags, "runtime-id:"+globalconfig.GetRuntimeID())
})
}

Expand Down
2 changes: 2 additions & 0 deletions profiler/upload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"testing"
"time"

"gopkg.in/DataDog/dd-trace-go.v1/internal/globalconfig"
"gopkg.in/DataDog/dd-trace-go.v1/internal/version"

"github.com/stretchr/testify/assert"
Expand Down Expand Up @@ -75,6 +76,7 @@ func TestTryUpload(t *testing.T) {
fmt.Sprintf("runtime_compiler:%s", runtime.Compiler),
fmt.Sprintf("runtime_arch:%s", runtime.GOARCH),
fmt.Sprintf("runtime_os:%s", runtime.GOOS),
fmt.Sprintf("runtime-id:%s", globalconfig.GetRuntimeID()),
}, tags)
for k, v := range map[string]string{
"format": "pprof",
Expand Down