|
| 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 | +} |
0 commit comments