Skip to content

Commit

Permalink
[BUG] The documentation for enableDebug is incorrect, it should refer…
Browse files Browse the repository at this point in the history
…ence enableDebugExceptions #2014
  • Loading branch information
MSNev committed Mar 18, 2023
1 parent 034e895 commit 224db76
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 85 deletions.
7 changes: 6 additions & 1 deletion docs/upgrade/v3_BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ The SDK still uses internal polyfills for ES5 features that are not supported by

If your application is required to maintain support for IE8 (ES3) you WILL need to continue to use the latest v2.x (Supported) releases.

## Configuration changes

| Configuration | Change
|---------------|-----------------
| `enableDebugExceptions` | This configuration has been removed and now only `enableDebug` is not used, as previously documented for v2

## Behavior changes

| Function | Change
Expand Down Expand Up @@ -176,7 +182,6 @@ The previously exported namespaced globals have been replaced with a reduced set
- IDataSanitizer, DataSanitizer
- Use the individual `dataSanitizer` prefixed functions that are also exported in later v2 releases documented in the [Tree Shaking Recommendations](https://github.com/microsoft/ApplicationInsights-JS/blob/master/TreeShakingRecommendations.md).


### @microsoft/applicationinsights-core-js

All previously `@deprecated` marked functions and the legacy "global" cookie handling functions
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1257,6 +1257,7 @@ export class AnalyticsPluginTests extends AITestClass {

this.testCase({
name: "Timing Tests: Multiple startTrackPage",
useFakeTimers: true,
test:
() => {
// setup
Expand All @@ -1274,7 +1275,8 @@ export class AnalyticsPluginTests extends AITestClass {
const appInsights = new AnalyticsPlugin();
core.addPlugin(appInsights);
const logStub = this.sandbox.stub(core.logger, "throwInternal");
core.logger.consoleLoggingLevel = () => 999;
core.config.loggingLevelConsole = 999;
this.clock.tick(1);

// act
appInsights.startTrackPage();
Expand All @@ -1287,6 +1289,7 @@ export class AnalyticsPluginTests extends AITestClass {

this.testCase({
name: "Timing Tests: stopTrackPage called without a corresponding start",
useFakeTimers: true,
test:
() => {
// setup
Expand All @@ -1304,7 +1307,8 @@ export class AnalyticsPluginTests extends AITestClass {
const appInsights = new AnalyticsPlugin();
core.addPlugin(appInsights);
const logStub = this.sandbox.stub(core.logger, "throwInternal");
core.logger.consoleLoggingLevel = () => 999;
core.config.loggingLevelConsole = 999;
this.clock.tick(1);

// act
appInsights.stopTrackPage();
Expand Down
42 changes: 21 additions & 21 deletions shared/AppInsightsCore/Tests/Unit/src/DynamicConfig.Tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -517,59 +517,59 @@ export class DynamicConfigTests extends AITestClass {
let theConfig: IConfiguration = {
instrumentationKey: "testiKey",
endpointUrl: "https://localhost:9001",
enableDebugExceptions: false,
enableDebug: false,
loggingLevelConsole: 1
};

const channelPlugin = new TestChannelPlugin();
let core = new AppInsightsCore();
let expectedEnableDebugExceptions = theConfig.enableDebugExceptions;
let expectedEnableDebug = theConfig.enableDebug;
let expectedLoggingLevel = theConfig.loggingLevelConsole;

core.initialize(theConfig, [channelPlugin]);
let onChangeCalled = 0;
let handler = core.onCfgChange((details) => {
onChangeCalled ++;
Assert.equal(expectedEnableDebugExceptions, details.cfg.enableDebugExceptions, "Expect the endpoint to be set");
if (details.cfg.enableDebugExceptions) {
Assert.equal(expectedEnableDebug, details.cfg.enableDebug, "Expect the endpoint to be set");
if (details.cfg.enableDebug) {
Assert.equal(expectedLoggingLevel, details.cfg.loggingLevelConsole, "Expected the logging level console")
}
});

Assert.equal(1, onChangeCalled, "OnCfgChange was not called");

// This should not trigger the listener as enableDebugExceptions was false
// This should not trigger the listener as enableDebug was false
expectedLoggingLevel = 99;
core.config.loggingLevelConsole = expectedLoggingLevel;

this.clock.tick(10);
Assert.equal(1, onChangeCalled, "listener should not have been called as enableDebugExceptions was false");
Assert.equal(1, onChangeCalled, "listener should not have been called as enableDebug was false");

// Enable Debug extensions
expectedEnableDebugExceptions = true;
core.config.enableDebugExceptions = expectedEnableDebugExceptions;
expectedEnableDebug = true;
core.config.enableDebug = expectedEnableDebug;
this.clock.tick(10);
Assert.equal(2, onChangeCalled, "listener should have been called enableDebugExceptions");
Assert.equal(2, onChangeCalled, "listener should have been called enableDebug");

// This should trigger the listener as enableDebugExceptions was false
// This should trigger the listener as enableDebug was false
expectedLoggingLevel = 2;
core.config.loggingLevelConsole = expectedLoggingLevel;

this.clock.tick(10);
Assert.equal(3, onChangeCalled, "listener should have been called as enableDebugExceptions was true");
Assert.equal(3, onChangeCalled, "listener should have been called as enableDebug was true");

// Disable Debug extensions again
expectedEnableDebugExceptions = false;
core.config.enableDebugExceptions = expectedEnableDebugExceptions;
expectedEnableDebug = false;
core.config.enableDebug = expectedEnableDebug;
this.clock.tick(10);
Assert.equal(4, onChangeCalled, "listener should have been called enableDebugExceptions");
Assert.equal(4, onChangeCalled, "listener should have been called enableDebug");

// This should not call trigger the listener as enableDebugExceptions was false
// This should not call trigger the listener as enableDebug was false
expectedLoggingLevel = 42;
core.config.loggingLevelConsole = expectedLoggingLevel;

this.clock.tick(10);
Assert.equal(4, onChangeCalled, "listener should have been called as enableDebugExceptions was disabled");
Assert.equal(4, onChangeCalled, "listener should have been called as enableDebug was disabled");
}
});

Expand All @@ -580,7 +580,7 @@ export class DynamicConfigTests extends AITestClass {
let theConfig: any = {
instrumentationKey: "testiKey",
endpointUrl: "https://localhost:9001",
enableDebugExceptions: false,
enableDebug: false,
loggingLevelConsole: 1,
extensionConfig: {
"test": {} as any
Expand Down Expand Up @@ -719,7 +719,7 @@ export class DynamicConfigTests extends AITestClass {
let theConfig: any = {
instrumentationKey: "testiKey",
endpointUrl: "https://localhost:9001",
enableDebugExceptions: false,
enableDebug: false,
loggingLevelConsole: 1,
extensionConfig: {
"test": {} as any
Expand Down Expand Up @@ -773,7 +773,7 @@ export class DynamicConfigTests extends AITestClass {
let theConfig: any = {
instrumentationKey: "testiKey",
endpointUrl: "https://localhost:9001",
enableDebugExceptions: false,
enableDebug: false,
loggingLevelConsole: 1,
extensionConfig: {
"test": {} as any
Expand Down Expand Up @@ -873,7 +873,7 @@ export class DynamicConfigTests extends AITestClass {
let theConfig: any = {
instrumentationKey: "testiKey",
endpointUrl: "https://localhost:9001",
enableDebugExceptions: false,
enableDebug: false,
loggingLevelConsole: 1,
userCfg: undefined
};
Expand Down Expand Up @@ -966,7 +966,7 @@ export class DynamicConfigTests extends AITestClass {
let theConfig: any = {
instrumentationKey: "testiKey",
endpointUrl: "https://localhost:9001",
enableDebugExceptions: false,
enableDebug: false,
loggingLevelConsole: 1,
userCfg: undefined,
extensionConfig: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export interface IConfiguration {
/**
* If enabled, uncaught exceptions will be thrown to help with debugging
*/
enableDebugExceptions?: boolean;
enableDebug?: boolean;

/**
* Endpoint where telemetry data is sent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,14 @@ import { _InternalLogMessage } from "../JavaScriptSDK/DiagnosticLogger";
import { ITelemetryUpdateState } from "./ITelemetryUpdateState";

export interface IDiagnosticLogger {
/**
* When this is true the SDK will throw exceptions to aid in debugging.
*/
enableDebugExceptions: () => boolean;


/**
* 0: OFF
* 1: only critical (default)
* 2: critical + info
*/
consoleLoggingLevel: () => number;

/**
* 0: OFF (default)
* 1: CRITICAL
* 2: WARNING
*/
telemetryLoggingLevel: () => number;

/**
* The maximum number of internal messages allowed to be sent per page view
*/
maxInternalMessageLimit: () => number;

/**
* The internal logging queue
*/
Expand Down
48 changes: 6 additions & 42 deletions shared/AppInsightsCore/src/JavaScriptSDK/DiagnosticLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { IAppInsightsCore } from "../JavaScriptSDK.Interfaces/IAppInsightsCore";
import { IConfiguration } from "../JavaScriptSDK.Interfaces/IConfiguration";
import { IDiagnosticLogger } from "../JavaScriptSDK.Interfaces/IDiagnosticLogger";
import { ITelemetryUpdateState } from "../JavaScriptSDK.Interfaces/ITelemetryUpdateState";
import { IConfigDefaults } from "../applicationinsights-core-js";
import { getDebugExt } from "./DbgExtensionUtils";
import { getConsole, getJSON, hasJSON } from "./EnvUtils";
import { STR_EMPTY, STR_ERROR_TO_CONSOLE, STR_WARN_TO_CONSOLE } from "./InternalConstants";
Expand All @@ -28,16 +29,11 @@ const AiUserActionablePrefix = "AI: ";
*/
const AIInternalMessagePrefix = "AITR_";

/**
* Holds the current logger which will be used as the default if no logger is available
*/
let _currentLogger: IDiagnosticLogger = null;

const defaultValues = {
const defaultValues: IConfigDefaults<IConfiguration> = {
loggingLevelConsole: 0,
loggingLevelTelemetry: 1,
maxMessageLimit: 25,
enableDebugExceptions: false
enableDebug: false
}

function _sanitizeDiagnosticText(text: string) {
Expand Down Expand Up @@ -115,19 +111,13 @@ export class DiagnosticLogger implements IDiagnosticLogger {
let _loggingLevelConsole: number;
let _loggingLevelTelemetry: number;
let _maxInternalMessageLimit: number;
let _enableDebugExceptions: boolean;
let _enableDebug: boolean;

dynamicProto(DiagnosticLogger, this, (_self) => {
_setDefaultsFromConfig(config || {});

_self.consoleLoggingLevel = () => _loggingLevelConsole;

_self.telemetryLoggingLevel = () => _loggingLevelTelemetry;

_self.maxInternalMessageLimit = () => _maxInternalMessageLimit;

_self.enableDebugExceptions = () => _enableDebugExceptions;

/**
* This method will throw exceptions in debug mode or attempt to log the error as a console warning.
* @param severity - {LoggingSeverity} - The severity of the log message
Expand All @@ -136,7 +126,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
_self.throwInternal = (severity: LoggingSeverity, msgId: _InternalMessageId, msg: string, properties?: Object, isUserAct = false) => {
const message = new _InternalLogMessage(msgId, msg, isUserAct, properties);

if (_enableDebugExceptions) {
if (_enableDebug) {
throw dumpObj(message);
} else {
// Get the logging function and fallback to warnToConsole of for some reason errorToConsole doesn't exist
Expand Down Expand Up @@ -244,7 +234,7 @@ export class DiagnosticLogger implements IDiagnosticLogger {
_loggingLevelConsole = config.loggingLevelConsole;
_loggingLevelTelemetry = config.loggingLevelTelemetry;
_maxInternalMessageLimit = config.maxMessageLimit;
_enableDebugExceptions = config.enableDebugExceptions;
_enableDebug = config.enableDebug;
});
}

Expand All @@ -261,14 +251,6 @@ export class DiagnosticLogger implements IDiagnosticLogger {
});
}

/**
* When this is true the SDK will throw exceptions to aid in debugging.
*/
public enableDebugExceptions(): boolean {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
return false;
}

/**
* 0: OFF (default)
* 1: CRITICAL
Expand All @@ -279,24 +261,6 @@ export class DiagnosticLogger implements IDiagnosticLogger {
return 0;
}

/**
* 0: OFF
* 1: CRITICAL (default)
* 2: >= WARNING
*/
public telemetryLoggingLevel(): number {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
return 1;
}

/**
* The maximum number of internal messages allowed to be sent per page view
*/
public maxInternalMessageLimit(): number {
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging
return 25;
}

/**
* This method will throw exceptions in debug mode or attempt to log the error as a console warning.
* @param severity - {LoggingSeverity} - The severity of the log message
Expand Down
2 changes: 1 addition & 1 deletion shared/AppInsightsCore/src/applicationinsights-core-js.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,5 +96,5 @@ export { IDynamicConfigHandler } from "./Config/IDynamicConfigHandler";
export { IDynamicPropertyHandler } from "./Config/IDynamicPropertyHandler";
export { IWatchDetails, IWatcherHandler, WatcherFunction } from "./Config/IDynamicWatcher";
export { createDynamicConfig, onConfigChange } from "./Config/DynamicConfig";
export { getDynamicConfigHandler, blockDynamicConversion } from "./Config/DynamicSupport";
export { getDynamicConfigHandler, blockDynamicConversion, forceDynamicConversion } from "./Config/DynamicSupport";
export { cfgDfValidate, cfgDfMerge, cfgDfBoolean, cfgDfFunc, cfgDfString, cfgDfSet } from "./Config/ConfigDefaultHelpers";

0 comments on commit 224db76

Please sign in to comment.