-
Notifications
You must be signed in to change notification settings - Fork 1k
feat(instrumentation-xml-http-request): support migration to stable HTTP semconv, v1.23.1 #5662
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
Changes from all commits
b918b43
dba9449
6db9ffe
87d194e
a7aa3a4
ce94896
dc80ba5
adcb19e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| /* | ||
| * Copyright The OpenTelemetry Authors | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
| * You may obtain a copy of the License at | ||
| * | ||
| * https://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
|
|
||
| /* | ||
| * This file contains a copy of unstable semantic convention definitions | ||
| * used by this package. | ||
| * @see https://github.com/open-telemetry/opentelemetry-js/tree/main/semantic-conventions#unstable-semconv | ||
| */ | ||
|
|
||
| /** | ||
| * Deprecated, use one of `server.address`, `client.address` or `http.request.header.host` instead, depending on the usage. | ||
| * | ||
| * @example www.example.org | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by one of `server.address`, `client.address` or `http.request.header.host`, depending on the usage. | ||
| */ | ||
| export const ATTR_HTTP_HOST = 'http.host' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `http.request.method` instead. | ||
| * | ||
| * @example GET | ||
| * @example POST | ||
| * @example HEAD | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `http.request.method`. | ||
| */ | ||
| export const ATTR_HTTP_METHOD = 'http.method' as const; | ||
|
|
||
| /** | ||
| * The size of the request payload body in bytes. This is the number of bytes transferred excluding headers and is often, but not always, present as the [Content-Length](https://www.rfc-editor.org/rfc/rfc9110.html#field.content-length) header. For requests using transport encoding, this should be the compressed size. | ||
| * | ||
| * @example 3495 | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| */ | ||
| export const ATTR_HTTP_REQUEST_BODY_SIZE = 'http.request.body.size' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `http.request.body.size` instead. | ||
| * | ||
| * @example 5493 | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `http.request.body.size`. | ||
| */ | ||
| export const ATTR_HTTP_REQUEST_CONTENT_LENGTH_UNCOMPRESSED = | ||
| 'http.request_content_length_uncompressed' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `http.response.header.<key>` instead. | ||
| * | ||
| * @example 3495 | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `http.response.header.<key>`. | ||
| */ | ||
| export const ATTR_HTTP_RESPONSE_CONTENT_LENGTH = | ||
| 'http.response_content_length' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `url.scheme` instead. | ||
| * | ||
| * @example http | ||
| * @example https | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `url.scheme` instead. | ||
| */ | ||
| export const ATTR_HTTP_SCHEME = 'http.scheme' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `http.response.status_code` instead. | ||
| * | ||
| * @example 200 | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `http.response.status_code`. | ||
| */ | ||
| export const ATTR_HTTP_STATUS_CODE = 'http.status_code' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `url.full` instead. | ||
| * | ||
| * @example https://www.foo.bar/search?q=OpenTelemetry#SemConv | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `url.full`. | ||
| */ | ||
| export const ATTR_HTTP_URL = 'http.url' as const; | ||
|
|
||
| /** | ||
| * Deprecated, use `user_agent.original` instead. | ||
| * | ||
| * @example CERN-LineMode/2.15 libwww/2.17b3 | ||
| * @example Mozilla/5.0 (iPhone; CPU iPhone OS 14_7_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.1.2 Mobile/15E148 Safari/604.1 | ||
| * | ||
| * @experimental This attribute is experimental and is subject to breaking changes in minor releases of `@opentelemetry/semantic-conventions`. | ||
| * | ||
| * @deprecated Replaced by `user_agent.original`. | ||
| */ | ||
| export const ATTR_HTTP_USER_AGENT = 'http.user_agent' as const; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,8 @@ | |
| // These may be unified in the future. | ||
|
|
||
| import * as api from '@opentelemetry/api'; | ||
| import { getStringListFromEnv } from '@opentelemetry/core'; | ||
| import { URLLike } from '@opentelemetry/sdk-trace-web'; | ||
|
|
||
| const DIAG_LOGGER = api.diag.createComponentLogger({ | ||
| namespace: | ||
|
|
@@ -83,3 +85,60 @@ function getFormDataSize(formData: FormData): number { | |
| } | ||
| return size; | ||
| } | ||
|
|
||
| /** | ||
| * Normalize an HTTP request method string per `http.request.method` spec | ||
| * https://github.com/open-telemetry/semantic-conventions/blob/main/docs/http/http-spans.md#http-client-span | ||
| */ | ||
| export function normalizeHttpRequestMethod(method: string): string { | ||
| const knownMethods = getKnownMethods(); | ||
| const methUpper = method.toUpperCase(); | ||
| if (methUpper in knownMethods) { | ||
| return methUpper; | ||
| } else { | ||
| return '_OTHER'; | ||
| } | ||
| } | ||
|
|
||
| const DEFAULT_KNOWN_METHODS = { | ||
| CONNECT: true, | ||
| DELETE: true, | ||
| GET: true, | ||
| HEAD: true, | ||
| OPTIONS: true, | ||
| PATCH: true, | ||
| POST: true, | ||
| PUT: true, | ||
| TRACE: true, | ||
| }; | ||
| let knownMethods: { [key: string]: boolean }; | ||
| function getKnownMethods() { | ||
| if (knownMethods === undefined) { | ||
| const cfgMethods = getStringListFromEnv( | ||
|
Member
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. Is this usable in a web package? Or should this be configured programmatically like the OptIn config option?
Contributor
Author
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. Good point. It'll "work" but get So this should probably change. BTW, the same code exists in instrumentation-fetch currently. The spec says:
I'm not sure if this instrumentation qualifies for The alternative would be to have a
Member
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.
Yeah I'm catching different things in each one, with lots to review some things don't stand out the first time around 😅 I guess a config option would be the way to do it, though I don't love that if we can help it. 🤔
Member
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. Since this is new and already in the fetch instr I think it's okay to let it be as-is and we can look into it for a follow-up, and fix both of them at the same time.
Contributor
Author
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. I opened #5677 for this. |
||
| 'OTEL_INSTRUMENTATION_HTTP_KNOWN_METHODS' | ||
| ); | ||
| if (cfgMethods && cfgMethods.length > 0) { | ||
| knownMethods = {}; | ||
| cfgMethods.forEach(m => { | ||
| knownMethods[m] = true; | ||
| }); | ||
| } else { | ||
| knownMethods = DEFAULT_KNOWN_METHODS; | ||
| } | ||
| } | ||
| return knownMethods; | ||
| } | ||
|
|
||
| const HTTP_PORT_FROM_PROTOCOL: { [key: string]: string } = { | ||
| 'https:': '443', | ||
| 'http:': '80', | ||
| }; | ||
| export function serverPortFromUrl(url: URLLike): number | undefined { | ||
| const serverPort = Number(url.port || HTTP_PORT_FROM_PROTOCOL[url.protocol]); | ||
| // Guard with `if (serverPort)` because `Number('') === 0`. | ||
| if (serverPort && !isNaN(serverPort)) { | ||
| return serverPort; | ||
| } else { | ||
| return undefined; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.