-
Notifications
You must be signed in to change notification settings - Fork 419
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
Conversation
tracer/tracer.go
Outdated
|
||
t.metaMu.RLock() | ||
if t.meta != nil { | ||
meta = make(map[string]string) |
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.
make(map[string]string, len(t.meta))
to ensure we only need one alloc
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.
👍
|
||
// getAllMeta returns all the meta set by this tracer. | ||
// In most cases, it is nil. | ||
func (t *Tracer) getAllMeta() map[string]string { |
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.
@@ -282,6 +282,28 @@ 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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Agree, will update the tests, thanks for feedback.
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.
LGTM!
Release 2.1
This should make the go client on par with the Python & Ruby ones, allowing application to set per tracer meta values (AKA tags).