-
Notifications
You must be signed in to change notification settings - Fork 203
feat: http semconv opt in files #1547
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 14 commits into
open-telemetry:main
from
hannahramadan:http_semcon_opt_in_files
Jun 17, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ca200a9
feat: WIP semcon file re-structure
hannahramadan 0cbb1c4
feat: semconv testing
hannahramadan e6e970c
Clean up appraisal file
hannahramadan 7e5f4ff
Appease Rubocop
hannahramadan 3f3ff4e
Add README and consider database migration env vars
hannahramadan f1c9701
safe nav stability_opt_in
hannahramadan 62ce61e
Add tests for environment variable
hannahramadan 3cfcc1e
Appease rubocop
hannahramadan c990c28
Cleanup
hannahramadan 8f91e28
Merge branch 'main' into http_semcon_opt_in_files
hannahramadan b4f01bb
Test refactor
hannahramadan db05759
Merge branch 'http_semcon_opt_in_files' of https://github.com/hannahr…
hannahramadan 4f71d4b
update determine_semconv test
hannahramadan 577458f
Merge branch 'main' into http_semcon_opt_in_files
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
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
70 changes: 0 additions & 70 deletions
70
instrumentation/http/lib/opentelemetry/instrumentation/http/patches/client.rb
This file was deleted.
Oops, something went wrong.
33 changes: 0 additions & 33 deletions
33
instrumentation/http/lib/opentelemetry/instrumentation/http/patches/connection.rb
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
instrumentation/http/lib/opentelemetry/instrumentation/http/patches/dup/client.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,84 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module HTTP | ||
module Patches | ||
# Module using old and stable HTTP semantic conventions | ||
module Dup | ||
# Module to prepend to HTTP::Client for instrumentation | ||
module Client | ||
# Constant for the HTTP status range | ||
HTTP_STATUS_SUCCESS_RANGE = (100..399) | ||
|
||
def perform(req, options) | ||
uri = req.uri | ||
request_method = req.verb.to_s.upcase | ||
span_name = create_request_span_name(request_method, uri.path) | ||
|
||
attributes = { | ||
# old semconv | ||
'http.method' => request_method, | ||
'http.scheme' => uri.scheme, | ||
'http.target' => uri.path, | ||
'http.url' => "#{uri.scheme}://#{uri.host}", | ||
'net.peer.name' => uri.host, | ||
'net.peer.port' => uri.port, | ||
# stable semconv | ||
'http.request.method' => request_method, | ||
'url.scheme' => uri.scheme, | ||
'url.path' => uri.path, | ||
'url.full' => "#{uri.scheme}://#{uri.host}", | ||
'server.address' => uri.host, | ||
'server.port' => uri.port | ||
} | ||
attributes['url.query'] = uri.query unless uri.query.nil? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Queries weren't previously reported and can often be |
||
attributes.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes) | ||
|
||
tracer.in_span(span_name, attributes: attributes, kind: :client) do |span| | ||
OpenTelemetry.propagation.inject(req.headers) | ||
super.tap do |response| | ||
annotate_span_with_response!(span, response) | ||
end | ||
end | ||
end | ||
|
||
private | ||
|
||
def config | ||
OpenTelemetry::Instrumentation::HTTP::Instrumentation.instance.config | ||
end | ||
|
||
def annotate_span_with_response!(span, response) | ||
return unless response&.status | ||
|
||
status_code = response.status.to_i | ||
span.set_attribute('http.status_code', status_code) # old semconv | ||
span.set_attribute('http.response.status_code', status_code) # stable semconv | ||
span.status = OpenTelemetry::Trace::Status.error unless HTTP_STATUS_SUCCESS_RANGE.cover?(status_code) | ||
end | ||
|
||
def create_request_span_name(request_method, request_path) | ||
if (implementation = config[:span_name_formatter]) | ||
updated_span_name = implementation.call(request_method, request_path) | ||
updated_span_name.is_a?(String) ? updated_span_name : "HTTP #{request_method}" | ||
else | ||
"HTTP #{request_method}" | ||
end | ||
rescue StandardError | ||
"HTTP #{request_method}" | ||
end | ||
|
||
def tracer | ||
HTTP::Instrumentation.instance.tracer | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
40 changes: 40 additions & 0 deletions
40
instrumentation/http/lib/opentelemetry/instrumentation/http/patches/dup/connection.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,40 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright The OpenTelemetry Authors | ||
# | ||
# SPDX-License-Identifier: Apache-2.0 | ||
|
||
module OpenTelemetry | ||
module Instrumentation | ||
module HTTP | ||
module Patches | ||
# Module using old and stable HTTP semantic conventions | ||
module Dup | ||
# Module to prepend to HTTP::Connection for instrumentation | ||
module Connection | ||
def initialize(req, options) | ||
attributes = { | ||
# old semconv | ||
'net.peer.name' => req.uri.host, | ||
'net.peer.port' => req.uri.port, | ||
# stable semconv | ||
'server.address' => req.uri.host, | ||
'server.port' => req.uri.port | ||
}.merge!(OpenTelemetry::Common::HTTP::ClientContext.attributes) | ||
|
||
tracer.in_span('HTTP CONNECT', attributes: attributes) do | ||
super | ||
end | ||
end | ||
|
||
private | ||
|
||
def tracer | ||
HTTP::Instrumentation.instance.tracer | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end | ||
end |
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.
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 approach gives us a fresh HTTP instance on each run. Without this, a single HTTP instance receives all patches.