|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +const benchmark = require('./benchmark'); |
| 4 | +const opentelemetry = require('@opentelemetry/core'); |
| 5 | +const { BasicTracer, BatchSpanProcessor, InMemorySpanExporter, SimpleSpanProcessor } = require('@opentelemetry/tracing'); |
| 6 | +const { NodeTracer } = require('@opentelemetry/node'); |
| 7 | + |
| 8 | +const exporter = new InMemorySpanExporter(); |
| 9 | +const logger = new opentelemetry.NoopLogger(); |
| 10 | + |
| 11 | +const setups = [ |
| 12 | + { |
| 13 | + name: 'BasicTracer', |
| 14 | + tracer: new BasicTracer({ logger }) |
| 15 | + }, |
| 16 | + { |
| 17 | + name: 'NodeTracer', |
| 18 | + tracer: new NodeTracer({ logger }) |
| 19 | + } |
| 20 | +]; |
| 21 | + |
| 22 | +for (const setup of setups) { |
| 23 | + console.log(`Beginning ${setup.name} Benchmark...`); |
| 24 | + const tracer = setup.tracer; |
| 25 | + const suite = benchmark() |
| 26 | + .add('#startSpan', function () { |
| 27 | + const span = tracer.startSpan('op'); |
| 28 | + span.end(); |
| 29 | + }) |
| 30 | + .add('#startSpan:parent', function () { |
| 31 | + const span = tracer.startSpan('op'); |
| 32 | + const childSpan = tracer.startSpan('client-op', { parent: span }); |
| 33 | + childSpan.end(); |
| 34 | + span.end(); |
| 35 | + }) |
| 36 | + .add('#startSpan with attribute', function () { |
| 37 | + const span = tracer.startSpan('op'); |
| 38 | + span.setAttribute('attr-key-one', 'attr-value-one'); |
| 39 | + span.end(); |
| 40 | + }) |
| 41 | + .add('#startSpan with 30 attributes', function () { |
| 42 | + const span = tracer.startSpan('op'); |
| 43 | + for (let j = 0; j < 30; j++) { |
| 44 | + span.setAttribute('attr-key-' + j, 'attr-value-' + j); |
| 45 | + } |
| 46 | + span.end(); |
| 47 | + }) |
| 48 | + .add('#startSpan with 100 attributes', function () { |
| 49 | + const span = tracer.startSpan('op'); |
| 50 | + for (let j = 0; j < 100; j++) { |
| 51 | + span.setAttribute('attr-key-' + j, 'attr-value-' + j); |
| 52 | + } |
| 53 | + span.end(); |
| 54 | + }) |
| 55 | + .add('#startSpan with SimpleSpanProcessor', function () { |
| 56 | + const simpleSpanProcessor = new SimpleSpanProcessor(exporter); |
| 57 | + |
| 58 | + tracer.addSpanProcessor(simpleSpanProcessor); |
| 59 | + const span = tracer.startSpan('op'); |
| 60 | + span.end(); |
| 61 | + |
| 62 | + simpleSpanProcessor.shutdown(); |
| 63 | + }) |
| 64 | + .add('#startSpan with BatchSpanProcessor', function () { |
| 65 | + const batchSpanProcessor = new BatchSpanProcessor(exporter); |
| 66 | + |
| 67 | + tracer.addSpanProcessor(batchSpanProcessor); |
| 68 | + const span = tracer.startSpan('op'); |
| 69 | + span.end(); |
| 70 | + batchSpanProcessor.shutdown(); |
| 71 | + }); |
| 72 | + |
| 73 | + // run async |
| 74 | + suite.run({ async: false }); |
| 75 | +} |
0 commit comments