-
Notifications
You must be signed in to change notification settings - Fork 204
feat: NET::HTTP semantic convention stability migration #1572
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
Open
hannahramadan
wants to merge
8
commits into
open-telemetry:main
Choose a base branch
from
hannahramadan:net_http_semconv_stability_opt_in
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c3a7804
feat: NET::HTTP semantic convention stability migration
hannahramadan 18559cf
fix: rubocop
hannahramadan 5f7fc25
fix: refactor attributes merge
hannahramadan e223219
Merge branch 'main' into net_http_semconv_stability_opt_in
hannahramadan 633216e
Merge branch 'main' into net_http_semconv_stability_opt_in
hannahramadan 9d764d8
Merge branch 'main' into net_http_semconv_stability_opt_in
hannahramadan 0f6f5a5
Fix CI
hannahramadan 03545aa
Merge branch 'net_http_semconv_stability_opt_in' of https://github.co…
hannahramadan 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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
# To faclitate HTTP semantic convention stability migration, we are using | ||
# appraisal to test the different semantic convention modes along with different | ||
# HTTP 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 "net-http-#{mode}" do | ||
# NOOP - net-http is part of the Ruby standard library. | ||
# We are only using Appraisals to allow testing of the | ||
# different stability modes. The file and the Appraisal | ||
# gem can be removed once semconv migration is complete. | ||
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
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
130 changes: 130 additions & 0 deletions
130
...tation/net_http/lib/opentelemetry/instrumentation/net/http/patches/dup/instrumentation.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,130 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module Net | ||
module HTTP | ||
module Patches | ||
module Dup | ||
# Module to prepend to Net::HTTP for instrumentation | ||
module Instrumentation | ||
USE_SSL_TO_SCHEME = { false => 'http', true => 'https' }.freeze | ||
|
||
# Constant for the HTTP status range | ||
HTTP_STATUS_SUCCESS_RANGE = (100..399) | ||
|
||
def request(req, body = nil, &) | ||
# Do not trace recursive call for starting the connection | ||
return super unless started? | ||
|
||
return super if untraced? | ||
|
||
attributes = { | ||
OpenTelemetry::SemanticConventions::Trace::HTTP_METHOD => req.method, | ||
OpenTelemetry::SemanticConventions::Trace::HTTP_SCHEME => USE_SSL_TO_SCHEME[use_ssl?], | ||
OpenTelemetry::SemanticConventions::Trace::HTTP_TARGET => req.path, | ||
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => @address, | ||
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => @port, | ||
'http.request.method' => req.method, | ||
'url.scheme' => USE_SSL_TO_SCHEME[use_ssl?], | ||
'server.address' => @address, | ||
'server.port' => @port | ||
} | ||
path, query = split_path_and_query(req.path) | ||
attributes['url.path'] = path | ||
attributes['url.query'] = query if query | ||
|
||
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes) | ||
|
||
tracer.in_span( | ||
req.method, | ||
attributes: attributes, | ||
kind: :client | ||
) do |span| | ||
OpenTelemetry.propagation.inject(req) | ||
|
||
super.tap do |response| | ||
annotate_span_with_response!(span, response) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def connect | ||
return super if untraced? | ||
|
||
if proxy? | ||
conn_address = proxy_address | ||
conn_port = proxy_port | ||
else | ||
conn_address = address | ||
conn_port = port | ||
end | ||
|
||
attributes = { | ||
OpenTelemetry::SemanticConventions::Trace::NET_PEER_NAME => conn_address, | ||
OpenTelemetry::SemanticConventions::Trace::NET_PEER_PORT => conn_port, | ||
'server.address' => conn_address, | ||
'server.port' => conn_port | ||
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes) | ||
|
||
if use_ssl? && proxy? | ||
span_name = 'CONNECT' | ||
span_kind = :client | ||
else | ||
span_name = 'connect' | ||
span_kind = :internal | ||
end | ||
kaylareopelle marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
tracer.in_span(span_name, attributes: attributes, kind: span_kind) do | ||
super | ||
end | ||
end | ||
|
||
def annotate_span_with_response!(span, response) | ||
return unless response&.code | ||
|
||
status_code = response.code.to_i | ||
|
||
span.set_attribute(OpenTelemetry::SemanticConventions::Trace::HTTP_STATUS_CODE, status_code) | ||
span.set_attribute('http.response.status_code', status_code) | ||
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code) | ||
end | ||
|
||
def tracer | ||
Net::HTTP::Instrumentation.instance.tracer | ||
end | ||
|
||
def untraced? | ||
untraced_context? || untraced_host? | ||
end | ||
|
||
def untraced_host? | ||
return true if Net::HTTP::Instrumentation.instance.config[:untraced_hosts]&.any? do |host| | ||
host.is_a?(Regexp) ? host.match?(@address) : host == @address | ||
end | ||
|
||
false | ||
end | ||
|
||
def untraced_context? | ||
OpenTelemetry::Common::Utilities.untraced? | ||
end | ||
|
||
def split_path_and_query(path) | ||
path_and_query = path.split('?') | ||
|
||
[path_and_query[0], path_and_query[1]] | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
111 changes: 0 additions & 111 deletions
111
...umentation/net_http/lib/opentelemetry/instrumentation/net/http/patches/instrumentation.rb
This file was deleted.
Oops, something went wrong.
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.