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

[tracer] allowing SetMeta at tracer level #56

Merged
merged 3 commits into from
Apr 26, 2017
Merged

Conversation

ufoot
Copy link
Member

@ufoot ufoot commented Apr 19, 2017

This should make the go client on par with the Python & Ruby ones, allowing application to set per tracer meta values (AKA tags).

@ufoot ufoot added the enhancement quick change/addition that does not need full team approval label Apr 19, 2017
@ufoot ufoot requested review from LotharSee and talwai April 19, 2017 13:57
tracer/tracer.go Outdated

t.metaMu.RLock()
if t.meta != nil {
meta = make(map[string]string)
Copy link
Contributor

@clutchski clutchski Apr 19, 2017

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

Copy link
Member Author

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 {
Copy link
Contributor

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.

Copy link
Member Author

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) {
Copy link
Contributor

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)

Copy link
Member Author

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.

Copy link
Contributor

@LotharSee LotharSee left a comment

Choose a reason for hiding this comment

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

LGTM!

@ufoot ufoot merged commit a5a64ce into master Apr 26, 2017
@ufoot ufoot added this to the 0.3.1 milestone Apr 26, 2017
@palazzem palazzem deleted the christian/tracertags branch November 27, 2017 15:17
jdgordon pushed a commit to jdgordon/dd-trace-go that referenced this pull request May 31, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement quick change/addition that does not need full team approval
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants