-
Notifications
You must be signed in to change notification settings - Fork 226
feat: rest-client HTTP semantic convention stability migration #1568
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
Merged
kaylareopelle
merged 8 commits into
open-telemetry:main
from
hannahramadan:restclient_semconv_stability_migration
Jul 28, 2025
Merged
Changes from 6 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
37fed93
feat: rest-client HTTP semantic convention stability migration
hannahramadan dd68f8d
fix: rubocop whitespace fix
hannahramadan 8fec679
Merge branch 'main' into restclient_semconv_stability_migration
hannahramadan c710c7b
feat: update span name
hannahramadan 8104ccd
Merge branch 'restclient_semconv_stability_migration' of https://gith…
hannahramadan eaf2662
Merge branch 'main' into restclient_semconv_stability_migration
hannahramadan 1278cc5
Update instrumentation/restclient/README.md
hannahramadan 90d8d2b
Merge branch 'main' into restclient_semconv_stability_migration
kaylareopelle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,18 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| appraise 'rest-client-2.1' do | ||
| gem 'rest-client', '~> 2.1.0' | ||
| end | ||
| # To faclitate HTTP semantic convention stability migration, we are using | ||
| # appraisal to test the different semantic convention modes along with different | ||
| # gem versions. For more information on the semantic convention modes, see: | ||
| # https://opentelemetry.io/docs/specs/semconv/non-normative/http-migration/ | ||
|
|
||
| semconv_stability = %w[dup stable old] | ||
|
|
||
| semconv_stability.each do |mode| | ||
| appraise "rest-client-2.1_#{mode}" do | ||
| gem 'rest-client', '~> 2.1.0' | ||
| end | ||
|
|
||
| appraise 'rest-client-2.0' do | ||
| gem 'rest-client', '~> 2.0.0' | ||
| appraise "rest-client-2.0_#{mode}" do | ||
| gem 'rest-client', '~> 2.0.0' | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
...umentation/restclient/lib/opentelemetry/instrumentation/restclient/patches/dup/request.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| module OpenTelemetry | ||
| module Instrumentation | ||
| module RestClient | ||
| module Patches | ||
| module Dup | ||
| # Module to prepend to RestClient::Request for instrumentation | ||
| module Request | ||
| # Constant for the HTTP status range | ||
| HTTP_STATUS_SUCCESS_RANGE = (100..399) | ||
|
|
||
| def execute(&) | ||
| trace_request do |_span| | ||
| super | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def create_request_span | ||
| http_method = method.upcase | ||
| instrumentation_attrs = { | ||
| 'http.method' => http_method.to_s, | ||
| 'http.request.method' => http_method.to_s, | ||
| 'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url), | ||
| 'url.full' => OpenTelemetry::Common::Utilities.cleanse_url(url) | ||
| } | ||
| instrumentation_config = RestClient::Instrumentation.instance.config | ||
| instrumentation_attrs['peer.service'] = instrumentation_config[:peer_service] if instrumentation_config[:peer_service] | ||
| span = tracer.start_span( | ||
| http_method.to_s, | ||
| attributes: instrumentation_attrs.merge( | ||
| OpenTelemetry::Common::HTTP::ClientContext.attributes | ||
| ), | ||
| kind: :client | ||
| ) | ||
|
|
||
| OpenTelemetry::Trace.with_span(span) do | ||
| OpenTelemetry.propagation.inject(processed_headers) | ||
| end | ||
|
|
||
| span | ||
| end | ||
|
|
||
| def trace_request | ||
| span = create_request_span | ||
|
|
||
| yield(span).tap do |response| | ||
| # Verify return value is a response. | ||
| # If so, add additional attributes. | ||
| if response.is_a?(::RestClient::Response) | ||
| span.set_attribute('http.status_code', response.code) | ||
| span.set_attribute('http.response.status_code', response.code) | ||
| span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(response.code.to_i) | ||
| end | ||
| end | ||
| rescue ::RestClient::ExceptionWithResponse => e | ||
| span.set_attribute('http.status_code', e.http_code) | ||
| span.set_attribute('http.response.status_code', e.http_code) | ||
| span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(e.http_code.to_i) | ||
| raise e | ||
| ensure | ||
| span.finish | ||
| end | ||
|
|
||
| def tracer | ||
| RestClient::Instrumentation.instance.tracer | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
75 changes: 75 additions & 0 deletions
75
...umentation/restclient/lib/opentelemetry/instrumentation/restclient/patches/old/request.rb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| module OpenTelemetry | ||
| module Instrumentation | ||
| module RestClient | ||
| module Patches | ||
| module Old | ||
| # Module to prepend to RestClient::Request for instrumentation | ||
| module Request | ||
| # Constant for the HTTP status range | ||
| HTTP_STATUS_SUCCESS_RANGE = (100..399) | ||
|
|
||
| def execute(&) | ||
| trace_request do |_span| | ||
| super | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def create_request_span | ||
| http_method = method.upcase | ||
| instrumentation_attrs = { | ||
| 'http.method' => http_method.to_s, | ||
| 'http.url' => OpenTelemetry::Common::Utilities.cleanse_url(url) | ||
| } | ||
| instrumentation_config = RestClient::Instrumentation.instance.config | ||
| instrumentation_attrs['peer.service'] = instrumentation_config[:peer_service] if instrumentation_config[:peer_service] | ||
| span = tracer.start_span( | ||
| "HTTP #{http_method}", | ||
| attributes: instrumentation_attrs.merge( | ||
| OpenTelemetry::Common::HTTP::ClientContext.attributes | ||
| ), | ||
| kind: :client | ||
| ) | ||
|
|
||
| OpenTelemetry::Trace.with_span(span) do | ||
| OpenTelemetry.propagation.inject(processed_headers) | ||
| end | ||
|
|
||
| span | ||
| end | ||
|
|
||
| def trace_request | ||
| span = create_request_span | ||
|
|
||
| yield(span).tap do |response| | ||
| # Verify return value is a response. | ||
| # If so, add additional attributes. | ||
| if response.is_a?(::RestClient::Response) | ||
| span.set_attribute('http.status_code', response.code) | ||
| span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(response.code.to_i) | ||
| end | ||
| end | ||
| rescue ::RestClient::ExceptionWithResponse => e | ||
| span.set_attribute('http.status_code', e.http_code) | ||
| span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(e.http_code.to_i) | ||
| raise e | ||
| ensure | ||
| span.finish | ||
| end | ||
|
|
||
| def tracer | ||
| RestClient::Instrumentation.instance.tracer | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end |
73 changes: 0 additions & 73 deletions
73
instrumentation/restclient/lib/opentelemetry/instrumentation/restclient/patches/request.rb
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.