-
Notifications
You must be signed in to change notification settings - Fork 421
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
[tracer] allowing SetMeta at tracer level #56
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -282,6 +282,42 @@ func TestTracerServicesDisabled(t *testing.T) { | |
assert.Equal(0, len(transport.services)) | ||
} | ||
|
||
func TestTracerMeta(t *testing.T) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. One case to test: when we set a meta at the span-level which has the same key as one set as the tracer-level. And to test something closer to user-land, we should do asserts on spans only (and don't need getAllMeta) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agree, will update the tests, thanks for feedback. |
||
assert := assert.New(t) | ||
|
||
var nilTracer *Tracer | ||
nilTracer.SetMeta("key", "value") | ||
assert.Nil(nilTracer.getAllMeta(), "nil tracer should return nil meta") | ||
|
||
tracer, _ := getTestTracer() | ||
assert.Nil(tracer.getAllMeta(), "by default, no meta") | ||
tracer.SetMeta("env", "staging") | ||
|
||
span := tracer.NewRootSpan("pylons.request", "pylons", "/") | ||
assert.Equal("staging", span.GetMeta("env")) | ||
assert.Equal("", span.GetMeta("component")) | ||
span.Finish() | ||
assert.Equal(map[string]string{"env": "staging"}, tracer.getAllMeta(), "there should be one meta") | ||
|
||
tracer.SetMeta("component", "core") | ||
span = tracer.NewRootSpan("pylons.request", "pylons", "/") | ||
assert.Equal("staging", span.GetMeta("env")) | ||
assert.Equal("core", span.GetMeta("component")) | ||
span.Finish() | ||
assert.Equal(map[string]string{"env": "staging", "component": "core"}, tracer.getAllMeta(), "there should be two entries") | ||
|
||
tracer.SetMeta("env", "prod") | ||
span = tracer.NewRootSpan("pylons.request", "pylons", "/") | ||
assert.Equal("prod", span.GetMeta("env")) | ||
assert.Equal("core", span.GetMeta("component")) | ||
span.SetMeta("env", "sandbox") | ||
assert.Equal("sandbox", span.GetMeta("env")) | ||
assert.Equal("core", span.GetMeta("component")) | ||
span.Finish() | ||
|
||
assert.Equal(map[string]string{"env": "prod", "component": "core"}, tracer.getAllMeta(), "key1 should have been updated") | ||
} | ||
|
||
// BenchmarkConcurrentTracing tests the performance of spawning a lot of | ||
// goroutines where each one creates a trace with a parent and a child. | ||
func BenchmarkConcurrentTracing(b *testing.B) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to implement this one? We are dealing without it in Python and Ruby, so I'd vote to keep the API simple if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The reason it's here is locking, this way we use
RLock
within the tracer code, the span code does not have to worry about it. Should we not do this I think span code would have to deal internally with the private mutex. This is perfectly doable, but I tend to prefer having objects dealing with their mutex internally, and not require others to care about it.Additionnally, Python code uses https://github.com/DataDog/dd-trace-py/blob/master/ddtrace/tracer.py#L164 which calls https://github.com/DataDog/dd-trace-py/blob/master/ddtrace/span.py#L145 so it also has this deep copy, only it's done in span.py instead of tracer.py.
I can move the code to span.go if you want to, just exposing the reason it's here. Note that getAllMeta is private, it's not part of the API anyway.