Skip to content

Commit 6921d0d

Browse files
authored
Merge d0c0ae6 into c478c11
2 parents c478c11 + d0c0ae6 commit 6921d0d

File tree

5 files changed

+128
-0
lines changed

5 files changed

+128
-0
lines changed

experimental/packages/otlp-transformer/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"tdd": "npm run test -- --watch-extensions ts --watch",
2222
"test": "nyc ts-mocha -p tsconfig.json 'test/**/*.test.ts'",
2323
"test:browser": "karma start --single-run",
24+
"test:bench": "node test/performance/benchmark/index.js | tee .benchmark-results.txt",
2425
"prewatch": "node ../../../scripts/version-update.js",
2526
"watch": "tsc --build -w tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
2627
"peer-api-check": "node ../../../scripts/peer-api-check.js",
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const Benchmark = require('benchmark');
18+
const { createExportTraceServiceRequest } = require('../../../build/src');
19+
const { BasicTracerProvider } = require('@opentelemetry/sdk-trace-base');
20+
21+
const tracerProvider = new BasicTracerProvider();
22+
const tracer = tracerProvider.getTracer('test')
23+
24+
const suite = new Benchmark.Suite();
25+
26+
const span = createSpan();
27+
const spans = [];
28+
for (let i = 0; i < 100; i++) {
29+
spans.push(createSpan());
30+
}
31+
32+
suite.on('cycle', event => {
33+
console.log(String(event.target));
34+
});
35+
36+
suite.add('transform 1 span', function() {
37+
createExportTraceServiceRequest([span]);
38+
});
39+
40+
suite.add('transform 100 spans', function() {
41+
createExportTraceServiceRequest(spans);
42+
});
43+
44+
suite.run();
45+
46+
function createSpan() {
47+
const span = tracer.startSpan('span');
48+
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
49+
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'bbbbbbbbbbbbbbbbbbbb');
50+
span.setAttribute('cccccccccccccccccccc', 'cccccccccccccccccccc');
51+
span.setAttribute('dddddddddddddddddddd', 'dddddddddddddddddddd');
52+
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'eeeeeeeeeeeeeeeeeeee');
53+
span.setAttribute('ffffffffffffffffffff', 'ffffffffffffffffffff');
54+
span.setAttribute('gggggggggggggggggggg', 'gggggggggggggggggggg');
55+
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'hhhhhhhhhhhhhhhhhhhh');
56+
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'iiiiiiiiiiiiiiiiiiii');
57+
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'jjjjjjjjjjjjjjjjjjjj');
58+
span.end();
59+
60+
return span;
61+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/*
2+
* Copyright The OpenTelemetry Authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
const Benchmark = require('benchmark');
18+
const { BasicTracerProvider, BatchSpanProcessor } = require('../../../build/src');
19+
const { ExportResultCode } = require('@opentelemetry/core');
20+
21+
class NoopExporter {
22+
export(spans, resultCallback) {
23+
setTimeout(() => resultCallback({ code: ExportResultCode.SUCCESS }), 0);
24+
}
25+
26+
shutdown() {
27+
return this.forceFlush();
28+
}
29+
30+
forceFlush() {
31+
return Promise.resolve();
32+
}
33+
}
34+
35+
function createSpan() {
36+
const span = tracer.startSpan('span');
37+
span.setAttribute('aaaaaaaaaaaaaaaaaaaa', 'aaaaaaaaaaaaaaaaaaaa');
38+
span.setAttribute('bbbbbbbbbbbbbbbbbbbb', 'aaaaaaaaaaaaaaaaaaaa');
39+
span.setAttribute('cccccccccccccccccccc', 'aaaaaaaaaaaaaaaaaaaa');
40+
span.setAttribute('dddddddddddddddddddd', 'aaaaaaaaaaaaaaaaaaaa');
41+
span.setAttribute('eeeeeeeeeeeeeeeeeeee', 'aaaaaaaaaaaaaaaaaaaa');
42+
span.setAttribute('ffffffffffffffffffff', 'aaaaaaaaaaaaaaaaaaaa');
43+
span.setAttribute('gggggggggggggggggggg', 'aaaaaaaaaaaaaaaaaaaa');
44+
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
45+
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
46+
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
47+
span.end();
48+
}
49+
50+
const tracerProvider = new BasicTracerProvider();
51+
tracerProvider.addSpanProcessor(new BatchSpanProcessor(new NoopExporter()));
52+
const tracer = tracerProvider.getTracer('test')
53+
54+
const suite = new Benchmark.Suite('BatchSpanProcessor');
55+
56+
suite.on('cycle', event => {
57+
console.log(String(event.target));
58+
});
59+
60+
suite.add('BatchSpanProcessor process span', function() {
61+
createSpan();
62+
});
63+
64+
suite.run();

packages/opentelemetry-sdk-trace-base/test/performance/benchmark/index.js

+1
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@
1515
*/
1616

1717
require('./span');
18+
require('./BatchSpanProcessor');

packages/opentelemetry-sdk-trace-base/test/performance/benchmark/span.js

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ suite.add('create spans (10 attributes)', function() {
3838
span.setAttribute('hhhhhhhhhhhhhhhhhhhh', 'aaaaaaaaaaaaaaaaaaaa');
3939
span.setAttribute('iiiiiiiiiiiiiiiiiiii', 'aaaaaaaaaaaaaaaaaaaa');
4040
span.setAttribute('jjjjjjjjjjjjjjjjjjjj', 'aaaaaaaaaaaaaaaaaaaa');
41+
span.end();
4142
});
4243

4344
suite.run();

0 commit comments

Comments
 (0)