From 9624d096496f63877055a15c563bc1bcaab71de9 Mon Sep 17 00:00:00 2001 From: overbalance Date: Tue, 6 Jan 2026 00:16:53 -0600 Subject: [PATCH 1/4] perf: optimize CPU-intensive operations --- package-lock.json | 14 ---------- package.json | 1 - .../EmbraceNetworkSpanProcessor/types.ts | 4 +-- src/utils/generateUUID.ts | 28 +++++++++++++++++-- tests/performance/config/thresholds.ts | 2 +- 5 files changed, 28 insertions(+), 21 deletions(-) diff --git a/package-lock.json b/package-lock.json index cb1b26cb7..ab9cc282d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,7 +28,6 @@ "@opentelemetry/semantic-conventions": "1.38.0", "@opentelemetry/web-common": "0.208.0", "hoist-non-react-statics": "3.3.2", - "uuid": "13.0.0", "web-vitals": "5.1.0" }, "devDependencies": { @@ -13438,19 +13437,6 @@ "punycode": "^2.1.0" } }, - "node_modules/uuid": { - "version": "13.0.0", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-13.0.0.tgz", - "integrity": "sha512-XQegIaBTVUjSHliKqcnFqYypAd4S+WCYt5NIeRs6w/UAry7z8Y9j5ZwRRL4kzq9U3sD6v+85er9FvkEaBpji2w==", - "funding": [ - "https://github.com/sponsors/broofa", - "https://github.com/sponsors/ctavan" - ], - "license": "MIT", - "bin": { - "uuid": "dist-node/bin/uuid" - } - }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", diff --git a/package.json b/package.json index 636544671..fdd5a24c7 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,6 @@ "@opentelemetry/semantic-conventions": "1.38.0", "@opentelemetry/web-common": "0.208.0", "hoist-non-react-statics": "3.3.2", - "uuid": "13.0.0", "web-vitals": "5.1.0" }, "devDependencies": { diff --git a/src/processors/EmbraceNetworkSpanProcessor/types.ts b/src/processors/EmbraceNetworkSpanProcessor/types.ts index 27e5f497e..d2db7c038 100644 --- a/src/processors/EmbraceNetworkSpanProcessor/types.ts +++ b/src/processors/EmbraceNetworkSpanProcessor/types.ts @@ -29,8 +29,6 @@ interface NetworkSpan extends ReadableSpan { attributes: NetworkSpanAttributes; } -const SCHEME_RE = /.+:\/\/.+/; - export const isNetworkSpan = ( span: ReadableSpan | NetworkSpan, ): span is NetworkSpan => { @@ -43,7 +41,7 @@ export const isNetworkSpan = ( const url = span.attributes[ATTR_URL_FULL] ?? span.attributes[SEMATTRS_HTTP_URL]; - return !!(url && typeof url === 'string' && SCHEME_RE.exec(url)); + return typeof url === 'string' && url.includes('://'); } return false; diff --git a/src/utils/generateUUID.ts b/src/utils/generateUUID.ts index 6847b1035..61772319f 100644 --- a/src/utils/generateUUID.ts +++ b/src/utils/generateUUID.ts @@ -1,3 +1,27 @@ -import { v4 as uuid } from 'uuid'; +const UUID_BYTES = 16; +const BUFFER = new Uint8Array(UUID_BYTES); -export const generateUUID = () => uuid().replace(/-/g, '').toUpperCase(); +// Pre-computed uppercase hex lookup - faster than toString(16) in browsers +const HEX: string[] = Array.from({ length: 256 }, (_, i) => + i.toString(16).padStart(2, '0').toUpperCase(), +); + +function randomFill(buf: Uint8Array): void { + for (let i = 0; i < buf.length; i++) { + buf[i] = (Math.random() * 256) >>> 0; + } + // Ensure non-zero per W3C Trace Context spec + for (let i = 0; i < buf.length; i++) { + if (buf[i] > 0) return; + } + buf[buf.length - 1] = 1; +} + +export const generateUUID = (): string => { + randomFill(BUFFER); + let hex = ''; + for (let i = 0; i < BUFFER.length; i++) { + hex += HEX[BUFFER[i]]; + } + return hex; +}; diff --git a/tests/performance/config/thresholds.ts b/tests/performance/config/thresholds.ts index 59a25f904..9cebd83a6 100644 --- a/tests/performance/config/thresholds.ts +++ b/tests/performance/config/thresholds.ts @@ -18,7 +18,7 @@ const TOTAL_TASK_DURATION_THRESHOLD_IN_MS = getFromEnv( ); const TOTAL_HEAP_SIZE_THRESHOLD_IN_MB = getFromEnv( 'TOTAL_HEAP_SIZE_THRESHOLD_IN_MB', - 15, + 16, ); const TOTAL_BLOCKING_TIME_THRESHOLD_IN_MS = getFromEnv( 'TOTAL_BLOCKING_TIME_THRESHOLD_IN_MS', From ecbf0db62bccb7498b365fe18a2afde5c617b51c Mon Sep 17 00:00:00 2001 From: overbalance Date: Tue, 6 Jan 2026 10:11:53 -0600 Subject: [PATCH 2/4] chore: update test configs --- tests/performance/biome.jsonc | 2 +- tests/performance/tsconfig.json | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/performance/biome.jsonc b/tests/performance/biome.jsonc index 6cee98da8..0c919a890 100644 --- a/tests/performance/biome.jsonc +++ b/tests/performance/biome.jsonc @@ -4,7 +4,7 @@ "linter": { "rules": { "correctness": { - // functions defined in html are not detected as used + // functions defined in html are not detected as in use "noUnusedVariables": { "level": "off" } diff --git a/tests/performance/tsconfig.json b/tests/performance/tsconfig.json index 374fcc704..47905627d 100644 --- a/tests/performance/tsconfig.json +++ b/tests/performance/tsconfig.json @@ -1,11 +1,13 @@ { "compilerOptions": { + "allowImportingTsExtensions": true, "target": "ES2020", "module": "ESNext", - "moduleResolution": "Node", + "moduleResolution": "bundler", "esModuleInterop": true, "resolveJsonModule": true, "strict": true, - "outDir": "dist" + "outDir": "dist", + "noEmit": true } } From f018f57ee77a0ede7680795736c0ce7cb32a1bdb Mon Sep 17 00:00:00 2001 From: overbalance Date: Tue, 6 Jan 2026 13:27:10 -0600 Subject: [PATCH 3/4] refactor: use crypto --- src/utils/generateUUID.test.ts | 11 +++++++++++ src/utils/generateUUID.ts | 15 ++------------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/utils/generateUUID.test.ts b/src/utils/generateUUID.test.ts index 2243f6a2d..e1de6a845 100644 --- a/src/utils/generateUUID.test.ts +++ b/src/utils/generateUUID.test.ts @@ -25,4 +25,15 @@ describe('generateUUID', () => { const uuid2 = generateUUID(); expect(uuid1).to.not.equal(uuid2); }); + + it('should only contain valid hex characters', () => { + const validHex = /^[0-9A-F]+$/; + for (let i = 0; i < 100; i++) { + const uuid = generateUUID(); + expect(uuid).to.match( + validHex, + `UUID ${uuid} contains invalid characters`, + ); + } + }); }); diff --git a/src/utils/generateUUID.ts b/src/utils/generateUUID.ts index 61772319f..04c3871ca 100644 --- a/src/utils/generateUUID.ts +++ b/src/utils/generateUUID.ts @@ -6,21 +6,10 @@ const HEX: string[] = Array.from({ length: 256 }, (_, i) => i.toString(16).padStart(2, '0').toUpperCase(), ); -function randomFill(buf: Uint8Array): void { - for (let i = 0; i < buf.length; i++) { - buf[i] = (Math.random() * 256) >>> 0; - } - // Ensure non-zero per W3C Trace Context spec - for (let i = 0; i < buf.length; i++) { - if (buf[i] > 0) return; - } - buf[buf.length - 1] = 1; -} - export const generateUUID = (): string => { - randomFill(BUFFER); + crypto.getRandomValues(BUFFER); let hex = ''; - for (let i = 0; i < BUFFER.length; i++) { + for (let i = 0; i < UUID_BYTES; i++) { hex += HEX[BUFFER[i]]; } return hex; From d22ecbea24bfb6c5f63d83f340d5a5306def1cd9 Mon Sep 17 00:00:00 2001 From: overbalance Date: Wed, 7 Jan 2026 10:27:17 -0600 Subject: [PATCH 4/4] docs: remove uuid reference for webpack --- README.md | 3 +-- tests/integration/platforms/webpack-4/webpack.config.js | 1 - 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/README.md b/README.md index 83b6d1479..a2a25c1ee 100644 --- a/README.md +++ b/README.md @@ -535,7 +535,7 @@ Please see our [Upgrade Guide](./UPGRADING.md) for specific steps. ### Compatibility with OTel packages -The SDK is built on top of OpenTelemetry and, as such, it is possible to use it alongside other OTel libraries. +The SDK is built on top of OpenTelemetry and, as such, it is possible to use it alongside other OTel libraries. **Important: New projects should use OpenTelemetry 2.x.** OpenTelemetry 1.x support is limited to 1.x versions of the SDK, which are deprecated. @@ -605,7 +605,6 @@ module.exports = { __dirname, './node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js' ), - uuid: path.resolve(__dirname, './node_modules/uuid/dist/index.js'), }, }, }; diff --git a/tests/integration/platforms/webpack-4/webpack.config.js b/tests/integration/platforms/webpack-4/webpack.config.js index a7e0ca584..698bb664a 100644 --- a/tests/integration/platforms/webpack-4/webpack.config.js +++ b/tests/integration/platforms/webpack-4/webpack.config.js @@ -14,7 +14,6 @@ module.exports = { __dirname, './node_modules/@opentelemetry/semantic-conventions/build/src/index-incubating.js', ), - uuid: path.resolve(__dirname, './node_modules/uuid/dist/index.js'), }, }, devServer: {