Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ For notes on migrating to 2.x / 0.200.x see [the upgrade guide](doc/upgrade-to-2
### :house: Internal

* perf(sdk-trace-base): use Uint8Array for browser RandomIdGenerator [#6209](https://github.com/open-telemetry/opentelemetry-js/pull/6209) @overbalance
* test(sdk-trace-base): remove obsolete TypeScript and platform workarounds [#6327](https://github.com/open-telemetry/opentelemetry-js/pull/6327) @overbalance

## 2.5.0

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

import * as assert from 'assert';
import { Suite } from 'mocha';
import * as sinon from 'sinon';
import { SpanExporter } from '../../../src';
import { BatchSpanProcessor } from '../../../src/platform/browser/export/BatchSpanProcessor';
Expand All @@ -24,18 +25,19 @@ import {
setGlobalErrorHandler,
} from '@opentelemetry/core';

/**
* VisibilityState has been removed from TypeScript 4.6.0+
* So just defining a simple replacement
*/
type WebVisibilityState = 'visible' | 'hidden';
const isBrowser =
typeof window !== 'undefined' && typeof document !== 'undefined';

const describeDocument =
typeof document === 'object' ? describe : describe.skip;
function describeBrowser(title: string, fn: (this: Suite) => void) {
title = `Browser: ${title}`;
if (isBrowser) {
return describe(title, fn);
}
return describe.skip(title, fn);
}

describeDocument('BatchSpanProcessor - web main context', () => {
// TODO: change to DocumentVisibilityState when TypeScript is upgraded to 4.6+
let visibilityState: WebVisibilityState = 'visible';
describeBrowser('BatchSpanProcessor', () => {
let visibilityState: DocumentVisibilityState = 'visible';
let exporter: SpanExporter;
let processor: BatchSpanProcessor;
let forceFlushSpy: sinon.SinonStub;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,21 @@ class BatchSpanProcessor extends BatchSpanProcessorBase<BufferConfig> {
describe('BatchSpanProcessorBase', () => {
describe('constructor', () => {
it('should read defaults from environment', () => {
const exporter = new InMemorySpanExporter();
const bspConfig = {
OTEL_BSP_MAX_EXPORT_BATCH_SIZE: 256,
OTEL_BSP_SCHEDULE_DELAY: 2500,
};

let env: Record<string, any>;
if (global.process?.versions?.node === undefined) {
env = globalThis as unknown as Record<string, any>;
} else {
env = process.env as Record<string, any>;
}
Object.assign(process.env, bspConfig);

Object.entries(bspConfig).forEach(([k, v]) => {
env[k] = v;
});
const processor = new BatchSpanProcessor(new InMemorySpanExporter());

const processor = new BatchSpanProcessor(exporter);
assert.ok(processor instanceof BatchSpanProcessor);
assert.strictEqual(processor['_maxExportBatchSize'], 256);
assert.strictEqual(processor['_scheduledDelayMillis'], 2500);
processor.shutdown();

Object.keys(bspConfig).forEach(k => delete env[k]);
Object.keys(bspConfig).forEach(k => delete process.env[k]);
});
});
});