-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(opentelemetry): Update OpenTelemetry dependencies to
1.28.0
(#…
…14547) Updates all OpenTelemetry dependencies to 1.28.0, as well as all instrumentation except for prisma (which is a major from 5 to 6, so leaving this out for now...) to their latest version.
- Loading branch information
Showing
20 changed files
with
417 additions
and
248 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 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 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 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 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 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 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
157 changes: 157 additions & 0 deletions
157
packages/node/src/integrations/http/vendor/getRequestInfo.ts
This file contains 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,157 @@ | ||
/* eslint-disable complexity */ | ||
|
||
/** | ||
* Vendored in from https://github.com/open-telemetry/opentelemetry-js/commit/87bd98edd24c98a5fbb9a56fed4b673b7f17a724 | ||
*/ | ||
|
||
/* | ||
* 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. | ||
*/ | ||
import type { RequestOptions } from 'node:http'; | ||
import * as url from 'url'; | ||
import type { DiagLogger } from '@opentelemetry/api'; | ||
|
||
/** | ||
* Makes sure options is an url object | ||
* return an object with default value and parsed options | ||
* @param logger component logger | ||
* @param options original options for the request | ||
* @param [extraOptions] additional options for the request | ||
*/ | ||
export const getRequestInfo = ( | ||
logger: DiagLogger, | ||
options: url.URL | RequestOptions | string, | ||
extraOptions?: RequestOptions, | ||
): { | ||
origin: string; | ||
pathname: string; | ||
method: string; | ||
invalidUrl: boolean; | ||
optionsParsed: RequestOptions; | ||
} => { | ||
let pathname: string; | ||
let origin: string; | ||
let optionsParsed: RequestOptions; | ||
let invalidUrl = false; | ||
if (typeof options === 'string') { | ||
try { | ||
const convertedOptions = stringUrlToHttpOptions(options); | ||
optionsParsed = convertedOptions; | ||
pathname = convertedOptions.pathname || '/'; | ||
} catch (e) { | ||
invalidUrl = true; | ||
logger.verbose( | ||
'Unable to parse URL provided to HTTP request, using fallback to determine path. Original error:', | ||
e, | ||
); | ||
// for backward compatibility with how url.parse() behaved. | ||
optionsParsed = { | ||
path: options, | ||
}; | ||
pathname = optionsParsed.path || '/'; | ||
} | ||
|
||
origin = `${optionsParsed.protocol || 'http:'}//${optionsParsed.host}`; | ||
if (extraOptions !== undefined) { | ||
Object.assign(optionsParsed, extraOptions); | ||
} | ||
} else if (options instanceof url.URL) { | ||
optionsParsed = { | ||
protocol: options.protocol, | ||
hostname: | ||
typeof options.hostname === 'string' && options.hostname.startsWith('[') | ||
? options.hostname.slice(1, -1) | ||
: options.hostname, | ||
path: `${options.pathname || ''}${options.search || ''}`, | ||
}; | ||
if (options.port !== '') { | ||
optionsParsed.port = Number(options.port); | ||
} | ||
if (options.username || options.password) { | ||
optionsParsed.auth = `${options.username}:${options.password}`; | ||
} | ||
pathname = options.pathname; | ||
origin = options.origin; | ||
if (extraOptions !== undefined) { | ||
Object.assign(optionsParsed, extraOptions); | ||
} | ||
} else { | ||
optionsParsed = Object.assign({ protocol: options.host ? 'http:' : undefined }, options); | ||
|
||
const hostname = | ||
optionsParsed.host || | ||
(optionsParsed.port != null ? `${optionsParsed.hostname}${optionsParsed.port}` : optionsParsed.hostname); | ||
origin = `${optionsParsed.protocol || 'http:'}//${hostname}`; | ||
|
||
pathname = (options as url.URL).pathname; | ||
if (!pathname && optionsParsed.path) { | ||
try { | ||
const parsedUrl = new URL(optionsParsed.path, origin); | ||
pathname = parsedUrl.pathname || '/'; | ||
} catch (e) { | ||
pathname = '/'; | ||
} | ||
} | ||
} | ||
|
||
// some packages return method in lowercase.. | ||
// ensure upperCase for consistency | ||
const method = optionsParsed.method ? optionsParsed.method.toUpperCase() : 'GET'; | ||
|
||
return { origin, pathname, method, optionsParsed, invalidUrl }; | ||
}; | ||
|
||
/** | ||
* Mimics Node.js conversion of URL strings to RequestOptions expected by | ||
* `http.request` and `https.request` APIs. | ||
* | ||
* See https://github.com/nodejs/node/blob/2505e217bba05fc581b572c685c5cf280a16c5a3/lib/internal/url.js#L1415-L1437 | ||
* | ||
* @param stringUrl | ||
* @throws TypeError if the URL is not valid. | ||
*/ | ||
function stringUrlToHttpOptions(stringUrl: string): RequestOptions & { pathname: string } { | ||
// This is heavily inspired by Node.js handling of the same situation, trying | ||
// to follow it as closely as possible while keeping in mind that we only | ||
// deal with string URLs, not URL objects. | ||
const { hostname, pathname, port, username, password, search, protocol, hash, href, origin, host } = new URL( | ||
stringUrl, | ||
); | ||
|
||
const options: RequestOptions & { | ||
pathname: string; | ||
hash: string; | ||
search: string; | ||
href: string; | ||
origin: string; | ||
} = { | ||
protocol: protocol, | ||
hostname: hostname && hostname[0] === '[' ? hostname.slice(1, -1) : hostname, | ||
hash: hash, | ||
search: search, | ||
pathname: pathname, | ||
path: `${pathname || ''}${search || ''}`, | ||
href: href, | ||
origin: origin, | ||
host: host, | ||
}; | ||
if (port !== '') { | ||
options.port = Number(port); | ||
} | ||
if (username || password) { | ||
options.auth = `${decodeURIComponent(username)}:${decodeURIComponent(password)}`; | ||
} | ||
return options; | ||
} |
This file contains 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 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 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.