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/go-chi: customize span resource name for go-chi #1950

Merged
merged 2 commits into from
Jun 1, 2023

Conversation

opsengine
Copy link
Contributor

@opsengine opsengine commented Apr 28, 2023

What does this PR do?

Let the caller define how the resource name should be constructed, given the http.Request object. If WithResourceName is not used, the old behavior is preserved.

Motivation

Improve span resource names.

Describe how to test/QA your changes

Unit tests

Reviewer's Checklist

  • Changed code has unit tests for its functionality.
  • If this interacts with the agent in a new way, a system test has been added.

@opsengine opsengine force-pushed the chi-custom-resource-name branch 2 times, most recently from b3d2bc0 to f9e0b42 Compare May 3, 2023 06:52
@opsengine opsengine marked this pull request as ready for review May 3, 2023 20:09
@opsengine opsengine requested a review from a team May 3, 2023 20:09
@opsengine opsengine force-pushed the chi-custom-resource-name branch 3 times, most recently from 3d13029 to 76e54ae Compare May 9, 2023 17:07
@opsengine opsengine force-pushed the chi-custom-resource-name branch 2 times, most recently from 1f9bb73 to d3df1a6 Compare May 12, 2023 10:09
katiehockman
katiehockman previously approved these changes May 16, 2023
Copy link
Contributor

@katiehockman katiehockman left a comment

Choose a reason for hiding this comment

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

LGTM aside from the naming convention. Thanks!

Comment on lines 111 to 113
// WithResourceName specifies a function to use for determining the resource
// name of the span.
func WithResourceName(fn func(r *http.Request) string) Option {
Copy link
Contributor

Choose a reason for hiding this comment

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

Convention based on other integrations is to call this WithResourceNamer.
Example: https://pkg.go.dev/gopkg.in/DataDog/dd-trace-go.v1@v1.50.1/contrib/urfave/negroni#WithResourceNamer

(here and throughout, so line 28 would be resourceNamer instead

Copy link
Contributor

Choose a reason for hiding this comment

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

I don't see a test for the "unknown" resource name case. I realize this isn't new code that you added, but if it's feasible for you to add a test to ensure that it works the same as it did before in that case, it would be great.

Copy link
Contributor

Choose a reason for hiding this comment

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

I also unfortunately don't see a test for checking the ext.HTTPRoute, or the default resource name either 😢
Would it be possible for you to write those up? If not, let us know and I can help you with that.

@opsengine
Copy link
Contributor Author

@katiehockman thanks for the feedback. I added the missing tests and fixed code conventions.

@taowata
Copy link
Contributor

taowata commented May 22, 2023

Hi @opsengine,Thank you for your valuable contribution.
I noticed that your PR is targeting versions of go-chi before v5. I'm interested in seeing this enhancement extended to v5 as well. Do you plan to adapt this for chi.v5?

It's important to note that v5 already has a WithModifyResourceName function, so we'd need to ensure compatibility with this existing feature.

@katiehockman, I would appreciate your thoughts on this matter too.

@opsengine
Copy link
Contributor Author

It's important to note that v5 already has a WithModifyResourceName function, so we'd need to ensure compatibility with this existing feature.

I looked at WithModifyResourceName and it has a more limited interface because it won't give access to the http.Request object.

Do you plan to adapt this for chi.v5?

Not for the moment.

@taowata
Copy link
Contributor

taowata commented May 24, 2023

Thanks for clarifying the limitations of WithModifyResourceName and your current plans regarding chi.v5.

Given the widespread usage of chi.v5, I'm considering extending this enhancement to it. If you're open to it, I'd like to create a new PR to make this possible.

@opsengine
Copy link
Contributor Author

Yes, please go ahead :)

@opsengine
Copy link
Contributor Author

@katiehockman good to merge?

@zarirhamza zarirhamza added the apm:ecosystem contrib/* related feature requests or bugs label Jun 1, 2023
Copy link
Contributor

@zarirhamza zarirhamza left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you @opsengine for your contribution and it sounds like a great idea @taowata to extend similar functionality to v5 as well as you mentioned here

@ahmed-mez ahmed-mez merged commit 6a62d1f into DataDog:main Jun 1, 2023
katiehockman pushed a commit that referenced this pull request Jun 6, 2023
Co-authored-by: Angelo Marletta <angelo.marletta@coinbase.com>
Co-authored-by: Zarir Hamza <zarir.hamza@datadoghq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
apm:ecosystem contrib/* related feature requests or bugs
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants