Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Instrumentation performance #1354

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
9 changes: 7 additions & 2 deletions src/utils/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ export type InstrumentationInfo = {name: string; version: string};
export function populateInstrumentationInfo(
entry: Entry | Entry[]
): [Entry[], boolean] {
// Check if instrumentation data was already written once. This prevents also inspection of
// the entries for instrumentation data to prevent perf degradation
if (global.instrumentationWritten) {
return [arrify(entry), false];
}
// Update the flag indicating that instrumentation entry was already added once,
// so any subsequent calls to this method will not add a separate instrumentation log entry
let isWritten = setInstrumentationStatus(true);
Expand All @@ -64,7 +69,7 @@ export function populateInstrumentationInfo(
validateAndUpdateInstrumentation(info);
// Indicate that instrumentation info log entry already exists
// and that current library info was added to existing log entry
isInfoAdded = isWritten = true;
global.instrumentationWritten = isInfoAdded = isWritten = true;
losalex marked this conversation as resolved.
Show resolved Hide resolved
}
entries.push(entryItem);
}
Expand All @@ -74,7 +79,7 @@ export function populateInstrumentationInfo(
// instrumentation data for this library
if (!isWritten) {
entries.push(createDiagnosticEntry(undefined, undefined));
isInfoAdded = true;
global.instrumentationWritten = isInfoAdded = true;
}
return [entries, isInfoAdded];
}
Expand Down
2 changes: 2 additions & 0 deletions test/instrumentation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ const LONG_VERSION_TEST = VERSION_TEST + '.0.0.0.0.0.0.0.0.11.1.1-ALPHA';
describe('instrumentation_info', () => {
beforeEach(() => {
instrumentation.setInstrumentationStatus(false);
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).instrumentationWritten = false;
});

it('should generate library info properly by default', () => {
Expand Down
4 changes: 4 additions & 0 deletions test/log.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,8 @@ describe('Log', () => {

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

it('should set the partialSuccess properly for existing instrumentation record', async () => {
ENTRIES.push(instrumentation.createDiagnosticEntry(undefined, undefined));
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(global as any).instrumentationWritten = false;
await log.write(ENTRIES, OPTIONS);
assert(
log.logging.loggingService.writeLogEntries.calledOnceWith(
Expand Down