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

Add async http instrumentation #2272

Merged
merged 20 commits into from
Oct 20, 2023
Merged

Add async http instrumentation #2272

merged 20 commits into from
Oct 20, 2023

Conversation

tannalynn
Copy link
Contributor

@tannalynn tannalynn commented Oct 18, 2023

Adds instrumentation for async-http

resolves #1176

@tannalynn tannalynn marked this pull request as ready for review October 18, 2023 21:06
lib/new_relic/agent/http_clients/async_http_wrappers.rb Outdated Show resolved Hide resolved
lib/new_relic/agent/instrumentation/async_http.rb Outdated Show resolved Hide resolved
lib/new_relic/agent/instrumentation/async_http.rb Outdated Show resolved Hide resolved
lib/new_relic/agent/instrumentation/async_http.rb Outdated Show resolved Hide resolved
newrelic.yml Outdated Show resolved Hide resolved
test/multiverse/suites/async_http/Envfile Outdated Show resolved Hide resolved
kaylareopelle
kaylareopelle previously approved these changes Oct 19, 2023
Copy link
Contributor

@kaylareopelle kaylareopelle left a comment

Choose a reason for hiding this comment

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

GitHub is showing me "4" comments, so I think some of what shows up will be moot based on more recent changes!

lib/new_relic/agent/instrumentation/async_http.rb Outdated Show resolved Hide resolved
newrelic.yml Outdated Show resolved Hide resolved
Comment on lines +385 to +389
# Controls auto-instrumentation of Async::HTTP at start up.
# May be one of [auto|prepend|chain|disabled]
# instrumentation.async_http: auto

# Controls auto-instrumentation of the concurrent-ruby library at start up. May be
Copy link
Contributor

Choose a reason for hiding this comment

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

@tannalynn - Out of curiosity, did you add this manually or use the script? (If you used the script, I'm a bit concerned about why the first version was outdented one level)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used the generator originally, but there was a merge conflict so i had to copy it and put it back, it's very possible that i messed up the indentation when i resolved the merge conflict.

Comment on lines +34 to +36
LHOST = 'host'
UHOST = 'Host'
COLON = ':'
Copy link
Contributor

Choose a reason for hiding this comment

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

Not for this PR, but maybe it's time to move these constants to a shared location.

@kaylareopelle kaylareopelle self-requested a review October 19, 2023 19:36
@kaylareopelle kaylareopelle self-requested a review October 19, 2023 19:38
kaylareopelle
kaylareopelle previously approved these changes Oct 19, 2023
Co-authored-by: James Bunch <fallwith@gmail.com>
@github-actions
Copy link

SimpleCov Report

Coverage Threshold
Line 94.1% 94%
Branch 85.66% 85%

@tannalynn tannalynn merged commit aab41ab into dev Oct 20, 2023
26 checks passed
@trevorturk
Copy link

Exciting stuff, thank you!

/cc @ioquatix in case he's interested in having a look 👀

@fallwith fallwith deleted the add_async_http_instrumentation branch October 20, 2023 00:45
@ioquatix
Copy link

ioquatix commented Oct 20, 2023

Thanks for working on this.

I don't want to come across as negative as I think it's awesome someone is getting value from this, but:

  1. There is a chance instrumentation that's injected like this will break due to internal changes or interface changes.
  2. In order to deal with this, I created a gem, traces.
  3. That gem provides a generic interface for tracing traces and spans, and provides implementation specific backends e.g. traces-backend-open_telemetry, traces-backend-datadog.
  4. This ensures any tracing (including across service boundaries) is handled correctly and is compatible, as the tracing is provided by the library itself.

I'm cautious about monkey patching approaches as unless tested in non-production (non-instrumented) environments, can suddenly break on deploying to production. Ideally, we can implement traces-backend-newrelic?

@tannalynn
Copy link
Contributor Author

@ioquatix
Thanks for bringing this to our attention! I didn't realize that existed, I must have missed it when I looked originally, sorry about that! Before I started, I looked at the readme for async-http to see if there was anything built in for observability (like subscriptions or something like this) but didn't see anything mentioned so I ended up just approaching it the way we instrument most gems (with monkey patching and prepend options).

An initial question I have after a quick look at it: Is there a way to insert into the headers? I see there is a w3c trace context method built in, but the new relic ruby agent has other types of headers that we will need to insert into outgoing request headers in certain situations. I'm not sure if that would be possible though.

I'll have to spend a little time setting up my test app to use traces and see how the things looks when creating a span with the new relic ruby agent with the traces interface. Once I've had a chance to do that I'll have a better idea of if we'll be able to move our instrumentation there.

Thank you for pointing this out and letting us know about traces!

@ioquatix
Copy link

ioquatix commented Oct 20, 2023

If you use traces, you will get instrumentation across all the socketry gems where it's implemented.

It is not currently possible to inject headers. I don't think we should change this but maybe that's something that can be monkey patched for legacy code?

@tannalynn
Copy link
Contributor Author

Creating a new relic implementation of traces seems like it would be a great thing for us to do to get more visibility, so I've created an issue #2283 for us to work on it and tentatively plan to work on it next quarter.

As for being able to insert headers, the agent does that on the HTTP client side in order to then parse it out on the HTTP server side (presuming both client and server are instrumented by New Relic). This is something we need to do to support other new relic products (for example: synthetics monitoring https://newrelic.com/platform/synthetics). If that's not something we can do with traces, we'll have to carry on monkey patching for async http still.

@trevorturk
Copy link

Hello, I know it sounds like even more good stuff is coming later with #2283 but I wanted to say thank you for working on this feature. I just rolled out a NR gem update in an app where I'm using Async::HTTP heavily and things are working great. It's lovely having this extra visibility now -- I really missed that when migrating from Typhoeus. Thank you!

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

Successfully merging this pull request may close these issues.

Instrumenting Async::HTTP
5 participants