-
Notifications
You must be signed in to change notification settings - Fork 224
fix: HTTP unknown methods #1781
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
arielvalentin
wants to merge
5
commits into
open-telemetry:main
Choose a base branch
from
arielvalentin:http-methods-fix
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
5 commits
Select commit
Hold shift + click to select a range
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
86 changes: 86 additions & 0 deletions
86
instrumentation/ethon/lib/opentelemetry/instrumentation/ethon/http_helper.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,86 @@ | ||
| # frozen_string_literal: true | ||
|
|
||
| # Copyright The OpenTelemetry Authors | ||
| # | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| module OpenTelemetry | ||
| module Instrumentation | ||
| module Ethon | ||
| # Helper module for HTTP method normalization | ||
| # @api private | ||
| module HttpHelper | ||
| # Lightweight struct to hold span creation attributes | ||
| SpanCreationAttributes = Struct.new(:span_name, :normalized_method, :original_method, keyword_init: true) | ||
|
|
||
| # Pre-computed mapping to avoid string allocations during normalization | ||
| METHOD_CACHE = { | ||
| 'CONNECT' => 'CONNECT', | ||
| 'DELETE' => 'DELETE', | ||
| 'GET' => 'GET', | ||
| 'HEAD' => 'HEAD', | ||
| 'OPTIONS' => 'OPTIONS', | ||
| 'PATCH' => 'PATCH', | ||
| 'POST' => 'POST', | ||
| 'PUT' => 'PUT', | ||
| 'TRACE' => 'TRACE', | ||
| 'connect' => 'CONNECT', | ||
| 'delete' => 'DELETE', | ||
| 'get' => 'GET', | ||
| 'head' => 'HEAD', | ||
| 'options' => 'OPTIONS', | ||
| 'patch' => 'PATCH', | ||
| 'post' => 'POST', | ||
| 'put' => 'PUT', | ||
| 'trace' => 'TRACE', | ||
| :connect => 'CONNECT', | ||
| :delete => 'DELETE', | ||
| :get => 'GET', | ||
| :head => 'HEAD', | ||
| :options => 'OPTIONS', | ||
| :patch => 'PATCH', | ||
| :post => 'POST', | ||
| :put => 'PUT', | ||
| :trace => 'TRACE' | ||
| }.freeze | ||
|
|
||
| # Pre-computed span names for old semantic conventions to avoid allocations | ||
| OLD_SPAN_NAMES = { | ||
| 'CONNECT' => 'HTTP CONNECT', | ||
| 'DELETE' => 'HTTP DELETE', | ||
| 'GET' => 'HTTP GET', | ||
| 'HEAD' => 'HTTP HEAD', | ||
| 'OPTIONS' => 'HTTP OPTIONS', | ||
| 'PATCH' => 'HTTP PATCH', | ||
| 'POST' => 'HTTP POST', | ||
| 'PUT' => 'HTTP PUT', | ||
| 'TRACE' => 'HTTP TRACE' | ||
| }.freeze | ||
|
|
||
| private_constant :METHOD_CACHE, :OLD_SPAN_NAMES | ||
|
|
||
| # Prepares all span data for the specified semantic convention in a single call | ||
| # @param method [String, Symbol] The HTTP method | ||
| # @param semconv [Symbol] The semantic convention to use (:stable or :old) | ||
| # @return [SpanCreationAttributes] struct containing span_name, normalized_method, and original_method | ||
| def self.span_attrs_for(method, semconv: :stable) | ||
| normalized = METHOD_CACHE[method] | ||
| if normalized | ||
| span_name = semconv == :old ? OLD_SPAN_NAMES[normalized] : normalized | ||
| SpanCreationAttributes.new( | ||
| span_name: span_name, | ||
| normalized_method: normalized, | ||
| original_method: nil | ||
| ) | ||
| else | ||
| SpanCreationAttributes.new( | ||
| span_name: 'HTTP', | ||
| normalized_method: '_OTHER', | ||
| original_method: method.to_s | ||
| ) | ||
| end | ||
| end | ||
| end | ||
| end | ||
| 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
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
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.
@arielvalentin - I'm concerned about changing the span names and attributes for the "old" instrumentation. It seems to break the contract for the
OTEL_SEMCONV_STABILITY_OPT_INvar:What do you think about reverting the changes for the
oldmodules and leaving the changes fordupandnew?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.
Ok that makes sense. I can leave the span name alone in follow up PRs.
Please consider that the existing
oldimplementation does not follow the correct conventions for span names and should not have a prefix ofHTTP: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.
may provide hooks to allow custom logic to override the default span name is also something new to me 🤔