diff --git a/CHANGELOG.md b/CHANGELOG.md index 4c48f21a6e..53987c4169 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,8 @@ For experimental package changes, see the [experimental CHANGELOG](experimental/ ### :house: (Internal) +* test: added a performance benchmark test for span creation [#4105](https://github.com/open-telemetry/opentelemetry-js/pull/4105) + ## 1.17.0 ### :bug: (Bug Fix) diff --git a/package.json b/package.json index fb734e564d..6d5460207d 100644 --- a/package.json +++ b/package.json @@ -15,6 +15,7 @@ "test:browser": "lerna run test:browser", "test:webworker": "lerna run test:webworker", "test:backcompat": "lerna run test:backcompat", + "test:bench": "lerna run test:bench", "bootstrap": "lerna bootstrap --hoist --nohoist='zone.js'", "changelog": "lerna-changelog", "codecov": "lerna run codecov", @@ -65,6 +66,7 @@ "devDependencies": { "@typescript-eslint/eslint-plugin": "5.59.11", "@typescript-eslint/parser": "5.59.11", + "benchmark": "2.1.4", "eslint": "8.44.0", "eslint-config-prettier": "9.0.0", "eslint-plugin-header": "3.1.1", diff --git a/packages/opentelemetry-sdk-trace-base/package.json b/packages/opentelemetry-sdk-trace-base/package.json index 77e7a64c28..600caa4294 100644 --- a/packages/opentelemetry-sdk-trace-base/package.json +++ b/packages/opentelemetry-sdk-trace-base/package.json @@ -20,6 +20,7 @@ "test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts' --exclude 'test/browser/**/*.ts'", "test:browser": "karma start --single-run", "test:webworker": "karma start karma.worker.js --single-run", + "test:bench": "node test/performance/benchmark/index.js", "tdd": "npm run tdd:node", "tdd:node": "npm run test -- --watch-extensions ts --watch", "tdd:browser": "karma start", diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js new file mode 100644 index 0000000000..83558ea01f --- /dev/null +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js @@ -0,0 +1,17 @@ +/* + * 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. + */ + +require('./span'); diff --git a/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js new file mode 100644 index 0000000000..ac978a6140 --- /dev/null +++ b/packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js @@ -0,0 +1,43 @@ +/* + * 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. + */ + +const Benchmark = require('benchmark'); +const { BasicTracerProvider } = require('../../../build/src'); + +const tracerProvider = new BasicTracerProvider(); +const tracer = tracerProvider.getTracer('test') + +const suite = new Benchmark.Suite(); + +suite.on('cycle', event => { + console.log(String(event.target)); +}); + +suite.add('create spans (10 attributes)', function() { + const span = tracer.startSpan('span'); + span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('cccccccccccccccccccc', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('dddddddddddddddddddd', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('ffffffffffffffffffff', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('gggggggggggggggggggg', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa'); + span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa'); +}); + +suite.run();