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/dimfeld/httptreemux/v5: add support for httptreemux #1546

Merged

Conversation

devilleweppenaar
Copy link
Contributor

Adding support to trace the dimfeld/httptreemux/v5 router package. The changes are almost identical to those that were required to instrument julienschmidt/httprouter, since httptreemux is based on httprouter.

Resolves #1520.

@devilleweppenaar
Copy link
Contributor Author

Hi friendly folks! 👋

Just wanted to check if there is anything needed from us for the time being? Looking forward to your initial review! 🙌

@ajgajg1134
Copy link
Contributor

Hello! The team does periodic proposal reviews where we go through the github issues marked with proposal (Which I've just added to your linked issue #1520). We'll leave comments there once we've evaluated it. Thanks!

@laughingman-hass
Copy link
Contributor

I would really love to see this PR merged

@ajgajg1134
Copy link
Contributor

We just looked at the proposal and accepted it! We'll do a full review of this PR soon :)

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.

Would you mind rebasing your branch? Thanks for your contribution! Just a few small comments, but overall this looks good.

if !math.IsNaN(cfg.analyticsRate) {
cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.EventSampleRate, cfg.analyticsRate))
}
cfg.spanOpts = append(cfg.spanOpts, tracer.Measured())
Copy link
Contributor

Choose a reason for hiding this comment

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

A few more spanOpts to add:

cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.SpanKind, ext.SpanKindServer))
cfg.spanOpts = append(cfg.spanOpts, tracer.Tag(ext.Component, "dimfeld/httptreemux.v5"))

https://github.com/DataDog/dd-trace-go/tree/main/contrib#usage

Copy link
Contributor

Choose a reason for hiding this comment

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

Same thing for ContextRouter

Copy link
Contributor Author

@devilleweppenaar devilleweppenaar Mar 23, 2023

Choose a reason for hiding this comment

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

  • add missing spanOpts to Router
  • add missing spanOpts to ContextRouter

Sorry, something went wrong.

Copy link
Contributor

Choose a reason for hiding this comment

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

All of this code should be in contrib/dimfeld/httptreemux.v5/ per our naming conventions: https://github.com/DataDog/dd-trace-go/tree/main/contrib#usage

Copy link
Contributor Author

@devilleweppenaar devilleweppenaar Mar 23, 2023

Choose a reason for hiding this comment

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

  • move contrib/dimfeld/httptreemux/v5/ to contrib/dimfeld/httptreemux.v5/
  • update references in log output

Sorry, something went wrong.

@devilleweppenaar
Copy link
Contributor Author

Thank you for the review and feedback @katiehockman! 🙌

I will work through the requested changes and submit an update as soon as possible.

Verified

This commit was signed with the committer’s verified signature.
rarguelloF Rodrigo Argüello
Adding support to trace the dimfeld/httptreemux/v5 router package. The changes
are almost identical to those that were required to instrument
julienschmidt/httprouter, since httptreemux is based on httprouter.

Resolves DataDog#1520

Verified

This commit was signed with the committer’s verified signature.
rarguelloF Rodrigo Argüello
Rename trace analytics enabled variable from
DD_TRACE_HTTPROUTER_ANALYTICS_ENABLED to
DD_TRACE_HTTPTREEMUX_ANALYTICS_ENABLED to correctly reflect what the
underlying routing package is.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add a default resource namer with the option to override it via the
router configuration.

Verified

This commit was signed with the committer’s verified signature.
rarguelloF Rodrigo Argüello
Update the defaultResourceNamer logic to exit early if the lookup
fails to find a match. Change test case input to avoid confusion
with the expected outcome.

Verified

This commit was signed with the committer’s verified signature.
rarguelloF Rodrigo Argüello
Rename the TestDefaultResourceNamer to TestHttpTracer404 as this
better reflects the intention.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
This fixes an issue where the paramater substitution would fail if a
parameter value was contained in the value of another.

For example given the path '/foo/:x/:y/bar' and the request URL
'/foo/123/2/bar', '2' is the value of parameter 'y' but also
contained in the value of parameter 'x', i.e. '123. This could lead
to a scenario where the resource name would be '/foo/1:y3/2/bar'
after the substitution.

Verified

This commit was signed with the committer’s verified signature.
rarguelloF Rodrigo Argüello
During review of the renamer change we discovered that the test could
fail intermittently depending on the random iteration order of
looping over items in the lookup params map.

We now first check to replace parameters surrounded by a set of '/',
i.e. '.../:param/...', and then move on to try and replace the
parameter at the end of the path without a trailing '/', i.e.
'../:param'.

This fix worked even if we ran the test multiple times.

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
Add support for ContextMux provided with dimfeld/httptreemux by
adding a new constructor function called NewWithContext. ContextMux
adds the matched route and parameters to the request context.

Unverified

No user is associated with the committer email.
Fixes a typo in the documentation of the ContextRouter struct.
@devilleweppenaar devilleweppenaar force-pushed the dv/1520/add-support-for-dimfeld-httptreemux branch from d4912d2 to 76e877f Compare March 23, 2023 17:46
devilleweppenaar and others added 5 commits March 23, 2023 11:05
Co-authored-by: Katie Hockman <katie@hockman.dev>
Anylytics rate is deprecated and can be safely removed.
Add span.kind and component tags that are
required to be set by all spans that are
generated by integrations.
Move integration code from
contrib/dimfeld/httptreemux/v5/ to
contrib/dimfeld/httptreemux.v5/ to
align with contribution guidelines.
Update comment and log statement references to
use the correct naming scheme, i.e.
contrib/dimfeld/httptreemux.v5.
@devilleweppenaar
Copy link
Contributor Author

Thanks again for the review and feedback @katiehockman. 🙌 I believe I have addressed all the points of feedback. Please take a look when you have a chance. 🙏

katiehockman
katiehockman previously approved these changes Mar 23, 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.

Thank you!!

@katiehockman katiehockman added this to the v1.49.0 milestone Mar 23, 2023
@katiehockman
Copy link
Contributor

Looks like there are some lint errors, but if you could fix those @devillexio then we should be good to merge!

Update to address linting error reported by
goimports.
@katiehockman katiehockman merged commit ab8566c into DataDog:main Mar 23, 2023
@katiehockman
Copy link
Contributor

Merged, thanks again @devillexio !!! 🎉

@devilleweppenaar devilleweppenaar deleted the dv/1520/add-support-for-dimfeld-httptreemux branch March 23, 2023 21:12
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.

contrib/dimfeld/httptreemux/v5: Add support for dimfeld/httptreemux
4 participants