-
Notifications
You must be signed in to change notification settings - Fork 247
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 rest-client
instrumentation adapter
#172
Add rest-client
instrumentation adapter
#172
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a great start @grantbdev! A number of things have changed over the last week that helps to streamline setup and install instrumentation. A good portion of my suggestions are based on those improvements. As I went through this PR, I realized that there were some existing issues with the Faraday and Sinatra adapters and ultimately made #177 to address them. I reference that PR in a number of comments and it corrects a few issues in our current instrumentation "template".
adapters/restclient/lib/opentelemetry/adapters/restclient/patches/request.rb
Outdated
Show resolved
Hide resolved
adapters/restclient/lib/opentelemetry/adapters/restclient/patches/request.rb
Outdated
Show resolved
Hide resolved
adapters/restclient/lib/opentelemetry/adapters/restclient/adapter.rb
Outdated
Show resolved
Hide resolved
module RestClient | ||
class Adapter < OpenTelemetry::Instrumentation::Adapter | ||
install do |config| | ||
require_dependencies |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm taking a mental note of how. many times I see this in adapters. It might make sense to make this an optional part of the DSL at some point.
@mwear Thank you for the feedback! I've pushed up my changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I go through these adapters with a fine tooth comb, I find a few more holes in our instrumentation template. I noticed that we are not using Rubocop on the instrumentation adapters, which lead me to create #179. We should add it for all instumentation adapters (including this one). You can look at #173, but the basic approach will be to:
- add .rubocop.yml to the root directory, see https://github.com/open-telemetry/opentelemetry-ruby/blob/22ea74a5a435de9b63e6522ab8c6066223f0f172/adapters/faraday/.rubocop.yml
- add .rubocop.yml to the test directory, see https://github.com/open-telemetry/opentelemetry-ruby/blob/22ea74a5a435de9b63e6522ab8c6066223f0f172/adapters/faraday/test/.rubocop.yml
- update the Rakefile, see: https://github.com/open-telemetry/opentelemetry-ruby/blob/c07e5378de2c377103ee0749632bce4613c9e40a/adapters/faraday/Rakefile
- update the gemspec, see: https://github.com/open-telemetry/opentelemetry-ruby/blob/22ea74a5a435de9b63e6522ab8c6066223f0f172/adapters/faraday/opentelemetry-adapters-faraday.gemspec
- Add to the top level rake file, see: https://github.com/open-telemetry/opentelemetry-ruby/blob/c07e5378de2c377103ee0749632bce4613c9e40a/Rakefile
- Fix violations
adapters/faraday/lib/opentelemetry/adapters/faraday/middlewares/tracer_middleware.rb
Outdated
Show resolved
Hide resolved
adapters/restclient/lib/opentelemetry/adapters/restclient/patches/request.rb
Outdated
Show resolved
Hide resolved
@mwear Feedback addressed. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great @grantbdev. Thanks for working through my feedback as we hone our instrumentation template.
end | ||
|
||
OpenTelemetry::SDK.configure do |c| | ||
c.use 'OpenTelemetry::Adapters::Faraday', tracer_middleware: NoOp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
def trace_request # rubocop:disable Metrics/AbcSize, Metrics/MethodLength | ||
span = tracer.start_span( | ||
url, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will lead to high-cardinality span names. See: #175 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mwear We could use "HTTP #{METHOD_NAME}"
. If that sounds good I'll update both PRs.
Only other thing I can think of that would add specificity without introducing a lot more would be to include URL host/domain.
@mwear Updated this PR with lower-cardinality span names and a few other tweaks I've found from working on more adapters. Do you think we should add setting of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good call on setting span.status
. We should be doing that here and on the other http client spans. I had a couple of other comments.
adapters/restclient/lib/opentelemetry/adapters/restclient/adapter.rb
Outdated
Show resolved
Hide resolved
adapters/restclient/lib/opentelemetry/adapters/restclient/patches/request.rb
Show resolved
Hide resolved
@mwear Feedback addressed. |
PR updated to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's one last change now that the context prop PR has merged. You'll probably want to rebase, make the suggested change, and ensure things work.
adapters/faraday/lib/opentelemetry/adapters/faraday/middlewares/tracer_middleware.rb
Outdated
Show resolved
Hide resolved
adapters/faraday/lib/opentelemetry/adapters/faraday/middlewares/tracer_middleware.rb
Outdated
Show resolved
Hide resolved
@mwear PR updated and I made sure to use the block that provides the span context for I'm not sure that we have anything explicitly testing propagation, let me know if you have ideas on how to accomplish that. |
@grantbdev Thanks for bringing up propagation tests. It is something we should test and in general, we should port over applicable tests when converting Datadog instrumentation. Here is an example from dd-trace-rb: https://github.com/DataDog/dd-trace-rb/blob/master/spec/ddtrace/contrib/rest_client/request_patch_spec.rb#L196-L209 By default OpenTelemetry.propagation.http_injectors is empty, making inject effectively a no-op. You could setup a custom injector for your test, or you could just use the trace context injector. Currently, there is a debate as to whether or not trace context should be a default injector. You can use the Datadog test as template and setup an injector like so: before do
# these are currently empty, but this will future proof the test
@orig_injectors = OpenTelemetry.propagation.http_injectors
OpenTelemetry.propagation.http_injectors = [OpenTelemetry::Trace::Propagation.http_trace_context_injector]
end
after do
OpenTelemetry.propagation.http_injectors = @orig_injectors
end |
@mwear Tests added, let me know what you think. I wasn't sure if we should use the |
👀 ing good @grantbdev. Thanks for addressing all my feedback. I am slightly weirded out that the assertions check for Anyhow, I am happy with where this is. Would you like me to leave this open for you to take a look @fbogsany, or should I go ahead and merge? |
@mwear I think the capitalization is coming from the libraries. So far, all of them except |
This has been open for a bit and hasn't received any new comments. I'd like to merge it, but will need a rebase first. |
@mwear Rebased |
* Add datadog-porting-guide * Reflection on experiences implementing instrumentation adapters so far (faraday, sinatra, rack) * Update based on recent PR comments * e.g., #172 * Update with suggestions from PR * Make a note about runtime performance considerations * usually show up as requests in submitted PRs
Add `rest-client` instrumentation adapter based on the adapter for Faraday and `ddtrace` code for `rest-client`. The `rest-client` gem uses `restclient` internally for file and folder naming, so I used that style for most of the internal adapter code. `rest-client` is used for names referring to the gem name itself. Related to #67
Update `faraday` adapter to match changes in the `rest-client` adapter. In the example code, the install call is replaced to work with the structure changes from #175. Support for disabling span reporting via a custom override is no longer provided since there is not a need for it at this time. This also removes the need to support injection of custom middleware. In the tracer middleware, the HTTP method attribute value is set to an uppercase string to be compliant with the specification. The name of the span is set to "HTTP #{verb}" to reduce the cardinality of the span names as described in the spec. The span status is now set when the response is received. The span propagation is now done directly. Propagated headers are now tested.
Thanks @grantbdev! |
Overview
Add
rest-client
instrumentation adapter similar to the existing adapter for Faraday.The
rest-client
gem usesrestclient
internally for file/folder naming, so I used that style for the adapter code. The gem's README also titleizes the name as simply "REST Client", so that is used in some spots but if that is too confusing I could try to clarify or consolidate on a single name.Related