Skip to content
This repository was archived by the owner on Mar 11, 2026. It is now read-only.

Commit 9f14ea1

Browse files
authored
fix: Instrumentation performance (#1354)
* fix: Instrumentation performance * Rename instrumentationWritten
1 parent 5637ca3 commit 9f14ea1

3 files changed

Lines changed: 19 additions & 2 deletions

File tree

src/utils/instrumentation.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ declare const global: {[index: string]: any};
2626
// libraries related info.
2727
global.instrumentationAdded = false;
2828

29+
// The global variable to avoid records inspection once instrumentation already written to prevent perf impact
30+
global.shouldSkipInstrumentationCheck = false;
31+
2932
// The variable to hold cached library version
3033
let libraryVersion: string;
3134

@@ -46,6 +49,11 @@ export type InstrumentationInfo = {name: string; version: string};
4649
export function populateInstrumentationInfo(
4750
entry: Entry | Entry[]
4851
): [Entry[], boolean] {
52+
// Check if instrumentation data was already written once. This prevents also inspection of
53+
// the entries for instrumentation data to prevent perf degradation
54+
if (global.shouldSkipInstrumentationCheck) {
55+
return [arrify(entry), false];
56+
}
4957
// Update the flag indicating that instrumentation entry was already added once,
5058
// so any subsequent calls to this method will not add a separate instrumentation log entry
5159
let isWritten = setInstrumentationStatus(true);
@@ -64,7 +72,10 @@ export function populateInstrumentationInfo(
6472
validateAndUpdateInstrumentation(info);
6573
// Indicate that instrumentation info log entry already exists
6674
// and that current library info was added to existing log entry
67-
isInfoAdded = isWritten = true;
75+
global.shouldSkipInstrumentationCheck =
76+
isInfoAdded =
77+
isWritten =
78+
true;
6879
}
6980
entries.push(entryItem);
7081
}
@@ -74,7 +85,7 @@ export function populateInstrumentationInfo(
7485
// instrumentation data for this library
7586
if (!isWritten) {
7687
entries.push(createDiagnosticEntry(undefined, undefined));
77-
isInfoAdded = true;
88+
global.shouldSkipInstrumentationCheck = isInfoAdded = true;
7889
}
7990
return [entries, isInfoAdded];
8091
}

test/instrumentation.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ const LONG_VERSION_TEST = VERSION_TEST + '.0.0.0.0.0.0.0.0.11.1.1-ALPHA';
3030
describe('instrumentation_info', () => {
3131
beforeEach(() => {
3232
instrumentation.setInstrumentationStatus(false);
33+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
34+
(global as any).shouldSkipInstrumentationCheck = false;
3335
});
3436

3537
it('should generate library info properly by default', () => {

test/log.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,6 +556,8 @@ describe('Log', () => {
556556

557557
it('should set the partialSuccess properly for instrumentation record', async () => {
558558
instrumentation.setInstrumentationStatus(false);
559+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
560+
(global as any).shouldSkipInstrumentationCheck = false;
559561
await log.write(ENTRIES, OPTIONS);
560562
assert(
561563
log.logging.loggingService.writeLogEntries.calledOnceWith(
@@ -569,6 +571,8 @@ describe('Log', () => {
569571

570572
it('should set the partialSuccess properly for existing instrumentation record', async () => {
571573
ENTRIES.push(instrumentation.createDiagnosticEntry(undefined, undefined));
574+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
575+
(global as any).shouldSkipInstrumentationCheck = false;
572576
await log.write(ENTRIES, OPTIONS);
573577
assert(
574578
log.logging.loggingService.writeLogEntries.calledOnceWith(

0 commit comments

Comments
 (0)