Skip to content

Commit

Permalink
Validate maxExportBatchSize in BatchSpanProcessorBase (#3232)
Browse files Browse the repository at this point in the history
  • Loading branch information
samimusallam authored Sep 18, 2022
1 parent 7870438 commit 0074ee2
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ All notable changes to this project will be documented in this file.
* fix(sdk-trace-base): make span start times resistant to hrtime clock drift
[#3129](https://github.com/open-telemetry/opentelemetry-js/issues/3129)

* fix(sdk-trace-base): validate maxExportBatchSize in BatchSpanProcessorBase
[#3232](https://github.com/open-telemetry/opentelemetry-js/issues/3232)

### :books: (Refine Doc)

* docs(metrics): add missing metrics packages to SDK reference documentation [#3239](https://github.com/open-telemetry/opentelemetry-js/pull/3239) @dyladan
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
* limitations under the License.
*/

import { context, Context, TraceFlags } from '@opentelemetry/api';
import {context, Context, diag, TraceFlags} from '@opentelemetry/api';
import {
BindOnceFuture,
ExportResultCode,
getEnv,
globalErrorHandler,
suppressTracing,
unrefTimer,
unrefTimer
} from '@opentelemetry/core';
import { Span } from '../Span';
import { SpanProcessor } from '../SpanProcessor';
Expand Down Expand Up @@ -63,6 +63,11 @@ export abstract class BatchSpanProcessorBase<T extends BufferConfig> implements
: env.OTEL_BSP_EXPORT_TIMEOUT;

this._shutdownOnce = new BindOnceFuture(this._shutdown, this);

if (this._maxExportBatchSize > this._maxQueueSize) {
diag.warn('BatchSpanProcessor: maxExportBatchSize must be smaller or equal to maxQueueSize, setting maxExportBatchSize to match maxQueueSize');
this._maxExportBatchSize = this._maxQueueSize;
}
}

forceFlush(): Promise<void> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { diag, ROOT_CONTEXT } from '@opentelemetry/api';
import {
ExportResultCode,
loggingErrorHandler,
setGlobalErrorHandler,
setGlobalErrorHandler
} from '@opentelemetry/core';
import * as assert from 'assert';
import * as sinon from 'sinon';
Expand Down Expand Up @@ -435,4 +435,21 @@ describe('BatchSpanProcessorBase', () => {
});
});
});

describe('maxExportBatchSize', () => {
let processor: BatchSpanProcessor;

describe('when "maxExportBatchSize" is greater than "maxQueueSize"', () => {
beforeEach(() => {
processor = new BatchSpanProcessor(
exporter,{
maxExportBatchSize: 7,
maxQueueSize: 6,
});
});
it('should match maxQueueSize', () => {
assert.equal(processor['_maxExportBatchSize'], processor['_maxQueueSize']);
});
});
});
});

0 comments on commit 0074ee2

Please sign in to comment.