|
| 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(); |
0 commit comments