From b43ac9bb6c3106b5e7fc9b6ad5720669dd38aaba Mon Sep 17 00:00:00 2001 From: Daniel Dyla Date: Wed, 4 Oct 2023 11:45:45 -0400 Subject: [PATCH] Lint and fix browser tests --- .../src/export/BatchSpanProcessorBase.ts | 9 +-- .../export/BatchSpanProcessorBase.test.ts | 69 ++++++++++--------- 2 files changed, 39 insertions(+), 39 deletions(-) diff --git a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts index fef5c80dc0..b3cb0c7418 100644 --- a/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts +++ b/packages/opentelemetry-sdk-trace-base/src/export/BatchSpanProcessorBase.ts @@ -47,10 +47,7 @@ export abstract class BatchSpanProcessorBase private _shutdownOnce: BindOnceFuture; private _droppedSpansCount: number = 0; - constructor( - private readonly _exporter: SpanExporter, - config?: T - ) { + constructor(private readonly _exporter: SpanExporter, config?: T) { const env = getEnv(); this._maxExportBatchSize = typeof config?.maxExportBatchSize === 'number' @@ -204,8 +201,8 @@ export abstract class BatchSpanProcessorBase doExport(); } else { Promise.all( - pendingResources.map( - resource => resource.waitForAsyncAttributes?.() + pendingResources.map(resource => + resource.waitForAsyncAttributes?.() ) ).then(doExport, err => { globalErrorHandler(err); diff --git a/packages/opentelemetry-sdk-trace-base/test/common/export/BatchSpanProcessorBase.test.ts b/packages/opentelemetry-sdk-trace-base/test/common/export/BatchSpanProcessorBase.test.ts index be4ff15248..83fb3ebe44 100644 --- a/packages/opentelemetry-sdk-trace-base/test/common/export/BatchSpanProcessorBase.test.ts +++ b/packages/opentelemetry-sdk-trace-base/test/common/export/BatchSpanProcessorBase.test.ts @@ -16,7 +16,7 @@ import { diag, ROOT_CONTEXT } from '@opentelemetry/api'; import { - ExportResult, + ExportResult, ExportResultCode, loggingErrorHandler, setGlobalErrorHandler, @@ -506,41 +506,44 @@ describe('BatchSpanProcessorBase', () => { }); }); - describe('Concurrency', ()=> { + describe('Concurrency', () => { it('should only send a single batch at a time', async () => { - let callbacks: ((result: ExportResult) => void)[] = [] - let spans: ReadableSpan[] = [] + const callbacks: ((result: ExportResult) => void)[] = []; + const spans: ReadableSpan[] = []; const exporter: SpanExporter = { - export: async (exportedSpans: ReadableSpan[], resultCallback: (result: ExportResult) => void) => { - callbacks.push(resultCallback) - spans.push(...exportedSpans) + export: async ( + exportedSpans: ReadableSpan[], + resultCallback: (result: ExportResult) => void + ) => { + callbacks.push(resultCallback); + spans.push(...exportedSpans); }, shutdown: async () => {}, + }; + const processor = new BatchSpanProcessor(exporter, { + maxExportBatchSize: 5, + maxQueueSize: 6, + }); + const totalSpans = 50; + for (let i = 0; i < totalSpans; i++) { + const span = createSampledSpan(`${name}_${i}`); + processor.onStart(span, ROOT_CONTEXT); + processor.onEnd(span); } - const processor = new BatchSpanProcessor(exporter, { - maxExportBatchSize: 5, - maxQueueSize: 6, - }); - const totalSpans = 50; - for (let i = 0; i < totalSpans; i++) { - const span = createSampledSpan(`${name}_${i}`); - processor.onStart(span, ROOT_CONTEXT); - processor.onEnd(span); - } - assert.equal(callbacks.length, 1) - assert.equal(spans.length, 5) - callbacks[0]({ code: ExportResultCode.SUCCESS }) - await new Promise(resolve => setImmediate(resolve)) - // After the first batch completes we will have dropped a number - // of spans and the next batch will be smaller - assert.equal(callbacks.length, 2) - assert.equal(spans.length, 10) - callbacks[1]({ code: ExportResultCode.SUCCESS }) - - // We expect that all the other spans have been dropped - await new Promise(resolve => setImmediate(resolve)) - assert.equal(callbacks.length, 2) - assert.equal(spans.length, 10) - }) - }) + assert.equal(callbacks.length, 1); + assert.equal(spans.length, 5); + callbacks[0]({ code: ExportResultCode.SUCCESS }); + await new Promise(resolve => setTimeout(resolve, 0)); + // After the first batch completes we will have dropped a number + // of spans and the next batch will be smaller + assert.equal(callbacks.length, 2); + assert.equal(spans.length, 10); + callbacks[1]({ code: ExportResultCode.SUCCESS }); + + // We expect that all the other spans have been dropped + await new Promise(resolve => setTimeout(resolve, 0)); + assert.equal(callbacks.length, 2); + assert.equal(spans.length, 10); + }); + }); });