Skip to content

Commit

Permalink
[BUG] Multiple errors are getting thrown and swallowed during initial…
Browse files Browse the repository at this point in the history
…ization when no instrumentation Key is provided #1691
  • Loading branch information
MSNev committed Oct 19, 2021
1 parent 3773971 commit 459b2c0
Showing 1 changed file with 10 additions and 11 deletions.
21 changes: 10 additions & 11 deletions shared/AppInsightsCore/src/JavaScriptSDK/BaseCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { ICookieMgr } from "../JavaScriptSDK.Interfaces/ICookieMgr";
import { createCookieMgr } from "./CookieMgr";
import { arrForEach, isNullOrUndefined, toISOString, getSetValue, setValue, throwError, isNotTruthy, isFunction } from "./HelperFuncs";
import { strExtensionConfig, strIKey } from "./Constants";
import { DiagnosticLogger } from "./DiagnosticLogger";

const validationError = "Extensions must provide callback to initialize";

Expand Down Expand Up @@ -56,11 +57,8 @@ export class BaseCore implements IAppInsightsCore {
dynamicProto(BaseCore, this, (_self) => {
_self._extensions = new Array<IPlugin>();
_channelController = new ChannelController();
_self.logger = objCreateFn({
throwInternal: (severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) => { },
warnToConsole: (message: string) => { },
resetInternalMessageCount: () => { }
});
// Use a default logger so initialization errors are not dropped on the floor
_self.logger = new DiagnosticLogger();

_eventQueue = [];
_self.isInitialized = () => _isInitialized;
Expand All @@ -71,11 +69,16 @@ export class BaseCore implements IAppInsightsCore {
throwError("Core should not be initialized more than once");
}

if (logger) {
// Make sure we allocated the configured logger as soon as possible so that errors are reported as configured
_self.logger = logger;
}

_notificationManager = notificationManager;

if (!config || isNullOrUndefined(config.instrumentationKey)) {
throwError("Please provide instrumentation key");
}

_notificationManager = notificationManager;

// For backward compatibility only
_self[strNotificationManager] = notificationManager;
Expand All @@ -92,10 +95,6 @@ export class BaseCore implements IAppInsightsCore {
let extConfig = getSetValue(config, strExtensionConfig);
extConfig.NotificationManager = notificationManager;

if (logger) {
_self.logger = logger;
}

// Concat all available extensions
let allExtensions = [];
allExtensions.push(...extensions, ...config.extensions);
Expand Down

0 comments on commit 459b2c0

Please sign in to comment.