Skip to content

Commit

Permalink
Benchmark tests for trace OTLP transform and BatchSpanProcessor (#4218)
Browse files Browse the repository at this point in the history
Co-authored-by: Marc Pichler <[email protected]>
  • Loading branch information
martinkuba and pichlermarc authored Nov 9, 2023
1 parent c478c11 commit 654638a
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 0 deletions.
1 change: 1 addition & 0 deletions experimental/packages/otlp-transformer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"tdd": "npm run test -- --watch-extensions ts --watch",
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
"test:browser": "karma start --single-run",
"test:bench": "node test/performance/benchmark/index.js | tee .benchmark-results.txt",
"prewatch": "node ../../../scripts/version-update.js",
"watch": "tsc --build -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
"peer-api-check": "node ../../../scripts/peer-api-check.js",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*
* 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 { createExportTraceServiceRequest } = require('../../../build/src');
const { BasicTracerProvider } = require('@opentelemetry/sdk-trace-base');

const tracerProvider = new BasicTracerProvider();
const tracer = tracerProvider.getTracer('test')

const suite = new Benchmark.Suite();

const span = createSpan();
const spans = [];
for (let i = 0; i < 100; i++) {
spans.push(createSpan());
}

suite.on('cycle', event => {
console.log(String(event.target));
});

suite.add('transform 1 span', function() {
createExportTraceServiceRequest([span]);
});

suite.add('transform 100 spans', function() {
createExportTraceServiceRequest(spans);
});

suite.run();

function createSpan() {
const span = tracer.startSpan('span');
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbbbbb');
span.setAttribute('cccccccccccccccccccc', 'cccccccccccccccccccc');
span.setAttribute('dddddddddddddddddddd', 'dddddddddddddddddddd');
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeee');
span.setAttribute('ffffffffffffffffffff', 'ffffffffffffffffffff');
span.setAttribute('gggggggggggggggggggg', 'gggggggggggggggggggg');
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'hhhhhhhhhhhhhhhhhhhh');
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'iiiiiiiiiiiiiiiiiiii');
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'jjjjjjjjjjjjjjjjjjjj');
span.end();

return span;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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, BatchSpanProcessor } = require('../../../build/src');
const { ExportResultCode } = require('@opentelemetry/core');

class NoopExporter {
export(spans, resultCallback) {
setTimeout(() => resultCallback({ code: ExportResultCode.SUCCESS }), 0);
}

shutdown() {
return this.forceFlush();
}

forceFlush() {
return Promise.resolve();
}
}

function createSpan() {
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');
span.end();
}

const tracerProvider = new BasicTracerProvider();
tracerProvider.addSpanProcessor(new BatchSpanProcessor(new NoopExporter()));
const tracer = tracerProvider.getTracer('test')

const suite = new Benchmark.Suite('BatchSpanProcessor');

suite.on('cycle', event => {
console.log(String(event.target));
});

suite.add('BatchSpanProcessor process span', function() {
createSpan();
});

suite.run();
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
*/

require('./span');
require('./BatchSpanProcessor');
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ suite.add('create spans (10 attributes)', function() {
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
span.end();
});

suite.run();

0 comments on commit 654638a

Please sign in to comment.