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

contrib: Adding WithCustomTag to various integrations #1359

Merged
merged 23 commits into from
Aug 12, 2022

Conversation

ajgajg1134
Copy link
Contributor

Pulling from fork to local repo (#1309) This will allow our system tests to run

@ajgajg1134 ajgajg1134 added this to the Triage milestone Jun 27, 2022
@ajgajg1134 ajgajg1134 requested a review from a team June 27, 2022 19:36
@ajgajg1134 ajgajg1134 changed the title Duxing/with custom tag contrib: Adding WithCustomTag to various integrations Jun 27, 2022
@duxing
Copy link

duxing commented Jun 27, 2022

@ajgajg1134 thank you! finally all the tests were passed

Comment on lines 101 to 107

if c.cfg.tagFns != nil {
for key, tagFn := range c.cfg.tagFns {
opts = append(opts, tracer.Tag(key, tagFn(msg)))
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
if c.cfg.tagFns != nil {
for key, tagFn := range c.cfg.tagFns {
opts = append(opts, tracer.Tag(key, tagFn(msg)))
}
}
if c.cfg.tagFns != nil {
for key, tagFn := range c.cfg.tagFns {
opts = append(opts, tracer.Tag(key, tagFn(msg)))
}
}

Please see point 3 in https://github.com/DataDog/dd-trace-go/wiki/Style-guidelines#general-guidelines. Happy to discuss these guidelines at any time and happy to change them if we see any issues.

@@ -216,6 +216,13 @@ func (tp *traceParams) tryTrace(ctx context.Context, qtype queryType, query stri
tracer.SpanType(ext.SpanTypeSQL),
tracer.StartTime(startTime),
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here.

@@ -88,6 +89,16 @@ func WithChildSpansOnly() Option {
}
}

// WithCustomTag will attach the value to the span tagged by the key.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// WithCustomTag will attach the value to the span tagged by the key.
// WithCustomTag will attach the key:value tag to all spans.

Is this correct?

For some reason the current explanation is a bit confusing.

contrib/database/sql/option.go Show resolved Hide resolved
Comment on lines 29 to 39

ret := make([]tracer.StartSpanOption, len(cfg.tags)+len(opts))
i := 0
for _, opt := range opts {
ret[i] = opt
i++
}
for key, tag := range cfg.tags {
ret[i] = tracer.Tag(key, tag)
i++
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
ret := make([]tracer.StartSpanOption, len(cfg.tags)+len(opts))
i := 0
for _, opt := range opts {
ret[i] = opt
i++
}
for key, tag := range cfg.tags {
ret[i] = tracer.Tag(key, tag)
i++
}
ret := make([]tracer.StartSpanOption, 0, len(cfg.tags)+len(opts))
for _, opt := range opts {
ret = append(ret, opt)
}
for key, tag := range cfg.tags {
ret = append(ret, tracer.Tag(key, tag))
}

Why not append?

@@ -31,6 +49,7 @@ func startSpanFromContext(
tracer.Tag(tagMethodName, method),
tracer.SpanType(ext.AppTypeRPC),
)

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really needed?

Copy link

Choose a reason for hiding this comment

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

I didn't check the style guidance prior to submitting the PR.
it's my personal preference for better legibility. I will remove the empty lines

if cfg.tagFns == nil {
cfg.tagFns = make(map[string]func(db *gorm.DB) interface{})
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Same comment here about spacing around curly braces.

@duxing
Copy link

duxing commented Jun 29, 2022

@gbbr I've addressed your feedback on my own PR (#1309 ) but it's not reflected here.
(this PR is created since my own PR fails CI tests, creating noise)

@duxing
Copy link

duxing commented Jul 1, 2022

thank @ajgajg1134 for updating the branch.
@gbbr lmk if there's any outstanding comments that need to be addressed. I may have missed some of your feedback

Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

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

Thanks!

}
}()

_ = (<-c.Events()).(*kafka.Message)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ = (<-c.Events()).(*kafka.Message)
<-c.Events()

Why does it need a cast and a _? Or are you trying to test the type of the returned value, in which case ignore my comment.

Copy link

Choose a reason for hiding this comment

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

the object from the channel is not consumed and what you suggested is preferred.

opts = append(opts, tracer.Tag(key, tag))
}
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change

@@ -22,6 +22,21 @@ import (
"google.golang.org/grpc/status"
)

func addCustomTags(cfg *config, opts ...tracer.StartSpanOption) []tracer.StartSpanOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe this is better suited as a method on *config inside option.go?

// appendOpts creates a new set of StartSpanOptions by appending all options defined by configuration
// to opts.
func (cfg *config) appendOpts(opts ...tracer.StartSpanOption) []tracer.StartSpanOption {

You can probably include tracer.WithAnalytics into the body of this method because it seems to be added everywhere and is bound to config, unlike tracer.Measured() below. It will simplify things a bit.

Copy link

Choose a reason for hiding this comment

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

addressed

@@ -120,6 +120,14 @@ func after(db *gorm.DB, operationName string, cfg *config) {
opts = append(opts, tracer.Tag(ext.EventSampleRate, cfg.analyticsRate))
}

if cfg.tagFns != nil {
for key, tagFn := range cfg.tagFns {
if tagFn != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

You are already checking nil in option.go. Is it necessary here too?

Copy link

@duxing duxing Jul 5, 2022

Choose a reason for hiding this comment

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

it still is in case WithCustomTag is never invoked.
but I do prefer creating an empty map as default config to avoid this nil check. it would also prevent concurrency issue

@duxing
Copy link

duxing commented Jul 5, 2022

sorry to bother you again @ajgajg1134: I've addressed @gbbr 's feedback on my branch (#1309 )
can you pull and update this PR? Thanks in advance!

@ajgajg1134
Copy link
Contributor Author

👍 sorry for the delay @duxing , I've just merged the changes in

@duxing
Copy link

duxing commented Jul 14, 2022

thx @ajgajg1134 !

@gbbr can you take another look? I'd love to see these methods being available in the next release.

@duxing
Copy link

duxing commented Jul 29, 2022

hi @gbbr ! it's been almost a month since I got your last feedback. Can you take another look?

@duxing
Copy link

duxing commented Aug 11, 2022

hi @ajgajg1134 @gbbr

any updates on this PR?

gbbr
gbbr previously approved these changes Aug 12, 2022
Copy link
Contributor

@gbbr gbbr left a comment

Choose a reason for hiding this comment

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

LGTM! Sorry for the delay!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants