-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(opentelemetry): Update OpenTelemetry dependencies to 1.28.0
#14547
Changes from all commits
6764d98
09b078e
8b5c111
48b359b
c6c61d6
827abf6
8bceeac
03a0279
bf29fb3
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 |
---|---|---|
|
@@ -28,18 +28,22 @@ test('AWS Serverless SDK sends events in ESM mode', async ({ request }) => { | |
expect(transactionEvent.contexts?.trace).toEqual({ | ||
data: { | ||
'sentry.sample_rate': 1, | ||
'sentry.source': 'component', | ||
'sentry.origin': 'auto.function.serverless', | ||
'sentry.source': 'custom', | ||
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. this now uses the proper OTEL instrumentation here! 🚀 |
||
'sentry.origin': 'auto.otel.aws-lambda', | ||
'sentry.op': 'function.aws.lambda', | ||
'cloud.account.id': '123453789012', | ||
'faas.id': 'arn:aws:lambda:us-east-1:123453789012:function:my-lambda', | ||
'faas.coldstart': true, | ||
'otel.kind': 'SERVER', | ||
}, | ||
op: 'function.aws.lambda', | ||
origin: 'auto.function.serverless', | ||
origin: 'auto.otel.aws-lambda', | ||
span_id: expect.stringMatching(/[a-f0-9]{16}/), | ||
status: 'ok', | ||
trace_id: expect.stringMatching(/[a-f0-9]{32}/), | ||
}); | ||
|
||
expect(transactionEvent.spans).toHaveLength(2); | ||
expect(transactionEvent.spans).toHaveLength(3); | ||
|
||
// shows that the Otel Http instrumentation is working | ||
expect(transactionEvent.spans).toContainEqual( | ||
|
@@ -54,6 +58,19 @@ test('AWS Serverless SDK sends events in ESM mode', async ({ request }) => { | |
}), | ||
); | ||
|
||
expect(transactionEvent.spans).toContainEqual( | ||
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. apparently our check |
||
expect.objectContaining({ | ||
data: { | ||
'sentry.op': 'function.aws.lambda', | ||
'sentry.origin': 'auto.function.serverless', | ||
'sentry.source': 'component', | ||
}, | ||
description: 'my-lambda', | ||
op: 'function.aws.lambda', | ||
origin: 'auto.function.serverless', | ||
}), | ||
); | ||
|
||
// shows that the manual span creation is working | ||
expect(transactionEvent.spans).toContainEqual( | ||
expect.objectContaining({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,7 @@ module.exports = { | |
testMatch: ['<rootDir>/**/*.test.ts', '<rootDir>/**/*.test.tsx'], | ||
moduleNameMapper: { | ||
'^axios$': require.resolve('axios'), | ||
'@opentelemetry/semantic-conventions/incubating': require.resolve('@opentelemetry/semantic-conventions/incubating'), | ||
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. this is needed to make this work with jest 😬 |
||
}, | ||
globals: { | ||
'ts-jest': { | ||
|
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; | ||
} |
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.
nice new attribute from the otel instrumentation!
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.
Documented here: https://github.com/getsentry/sentry-conventions/blob/main/model/attributes/faas/faas__coldstart.json