-
Notifications
You must be signed in to change notification settings - Fork 237
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
[BUG] Multiple errors are getting thrown and swallowed during initialization when no instrumentation Key is provided #1691 #1695
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,8 @@ const AiUserActionablePrefix = "AI: "; | |
*/ | ||
const AIInternalMessagePrefix = "AITR_"; | ||
|
||
const strErrorToConsole = "errorToConsole"; | ||
const strWarnToConsole = "warnToConsole"; | ||
|
||
function _sanitizeDiagnosticText(text: string) { | ||
if (text) { | ||
|
@@ -33,6 +35,20 @@ function _sanitizeDiagnosticText(text: string) { | |
return ""; | ||
} | ||
|
||
function _logToConsole(func: string, message: string) { | ||
let theConsole = getConsole(); | ||
if (!!theConsole) { | ||
let logFunc = "log"; | ||
if (theConsole[func]) { | ||
logFunc = "func"; | ||
} | ||
|
||
if (isFunction(theConsole[logFunc])) { | ||
theConsole[logFunc](message); | ||
} | ||
} | ||
} | ||
|
||
export class _InternalLogMessage{ | ||
public static dataType: string = "MessageData"; | ||
|
||
|
@@ -107,20 +123,23 @@ export class DiagnosticLogger implements IDiagnosticLogger { | |
if (_self.enableDebugExceptions()) { | ||
throw message; | ||
} else { | ||
// Get the logging function and fallback to warnToConsole of for some reason errorToConsole doesn't exist | ||
let logFunc = severity === LoggingSeverity.CRITICAL ? strErrorToConsole : strWarnToConsole; | ||
|
||
if (!isUndefined(message.message)) { | ||
const logLevel = _self.consoleLoggingLevel(); | ||
if (isUserAct) { | ||
// check if this message type was already logged to console for this page view and if so, don't log it again | ||
const messageKey: number = +message.messageId; | ||
|
||
if (!_messageLogged[messageKey] && logLevel >= LoggingSeverity.WARNING) { | ||
_self.warnToConsole(message.message); | ||
if (!_messageLogged[messageKey] && logLevel >= severity) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a bug as the "logLevel" is documented as 0 - zero == disabled, 1 - critical only and 2 - everything. The code as previously was treating 0 and 1 as disabled |
||
_self[logFunc](message.message); | ||
_messageLogged[messageKey] = true; | ||
} | ||
} else { | ||
// don't log internal AI traces in the console, unless the verbose logging is enabled | ||
if (logLevel >= LoggingSeverity.WARNING) { | ||
_self.warnToConsole(message.message); | ||
// Only log traces if the console Logging Level is >= the throwInternal severity level | ||
if (logLevel >= severity) { | ||
_self[logFunc](message.message); | ||
} | ||
} | ||
|
||
|
@@ -134,17 +153,15 @@ export class DiagnosticLogger implements IDiagnosticLogger { | |
* @param message {string} - The warning message | ||
*/ | ||
_self.warnToConsole = (message: string) => { | ||
let theConsole = getConsole(); | ||
if (!!theConsole) { | ||
let logFunc = "log"; | ||
if (theConsole.warn) { | ||
logFunc = "warn"; | ||
} | ||
_logToConsole("warn", message); | ||
} | ||
|
||
if (isFunction(theConsole[logFunc])) { | ||
theConsole[logFunc](message); | ||
} | ||
} | ||
/** | ||
* This will write an error to the console if possible | ||
* @param message {string} - The error message | ||
*/ | ||
_self.errorToConsole = (message: string) => { | ||
_logToConsole("error", message); | ||
} | ||
|
||
/** | ||
|
@@ -261,6 +278,14 @@ export class DiagnosticLogger implements IDiagnosticLogger { | |
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging | ||
} | ||
|
||
/** | ||
* This will write an error to the console if possible | ||
* @param message {string} - The warning message | ||
*/ | ||
public errorToConsole(message: string) { | ||
// @DynamicProtoStub -- DO NOT add any code as this will be removed during packaging | ||
} | ||
|
||
/** | ||
* Resets the internal message count | ||
*/ | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding new log to console as an error, so that critical errors are highlighted better.