-
Notifications
You must be signed in to change notification settings - Fork 239
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
[main] Adding round robin retry for snippet script src loading #2131
Merged
Merged
Changes from 8 commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
28f31c8
Update snippet.ts
siyuniu-ms 98d512b
reformat
siyuniu-ms cd3d09a
reduce string size
siyuniu-ms 6e7d1a5
Merge branch 'main' into siyu/snippetUpdate
siyuniu-ms 6da8314
Update snippet.ts
siyuniu-ms eaebdcf
Merge branch 'siyu/snippetUpdate' of https://github.com/microsoft/App…
siyuniu-ms 850142f
add config
siyuniu-ms c142555
change logic
siyuniu-ms da226b0
manual test works
siyuniu-ms 1289418
Update snippet.ts
siyuniu-ms 7b95e41
Update snippet.ts
siyuniu-ms c756e41
Merge branch 'main' into siyu/snippetUpdate
siyuniu-ms f4b532e
test version 2, works good, didn't find 3 link
siyuniu-ms 83f1a4c
Update snippet.ts
siyuniu-ms ff86633
build?
siyuniu-ms 0924a0e
Update type.ts
siyuniu-ms 882b972
Merge branch 'main' into siyu/snippetUpdate
siyuniu-ms 77a7c68
Update snippet.ts
siyuniu-ms f832f7d
Merge branch 'siyu/snippetUpdate' of https://github.com/microsoft/App…
siyuniu-ms c5d1c3e
Merge branch 'main' into siyu/snippetUpdate
siyuniu-ms 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,7 +98,7 @@ declare var cfg:ISnippetConfig; | |
let ingest = conString[strIngestionendpoint]; | ||
let endpointUrl = ingest ? ingest + "/v2/track" : aiConfig.endpointUrl; // only add /v2/track when from connectionstring | ||
|
||
let message = "SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)"; | ||
let message = "SDK LOAD Failure: Failed to load Application Insights SDK script via " + targetSrc + " (See stack for details)"; | ||
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. I don't think we need to add the targetSrc here as it gets included in the message details via the |
||
let evts:IEnvelope[] = []; | ||
evts.push(_createException(iKey, message, targetSrc, endpointUrl)); | ||
evts.push(_createInternal(iKey, message, targetSrc, endpointUrl)); | ||
|
@@ -183,6 +183,19 @@ declare var cfg:ISnippetConfig; | |
|
||
return envelope; | ||
} | ||
|
||
let domainRetryIndex = -1; | ||
let domains = [ | ||
"js.monitor.azure.com", | ||
siyuniu-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"js.cdn.applicationinsights.io", | ||
"js.cdn.monitor.azure.com", | ||
"js0.cdn.applicationinsights.io", | ||
"js0.cdn.monitor.azure.com", | ||
// "js1.cdn.monitor.azure.com", | ||
"js2.cdn.applicationinsights.io", | ||
"js2.cdn.monitor.azure.com", | ||
"az416426.vo.msecnd.net" | ||
] | ||
|
||
// Assigning these to local variables allows them to be minified to save space: | ||
let targetSrc : string = (aiConfig as any)["url"] || cfg.src | ||
|
@@ -194,12 +207,24 @@ declare var cfg:ISnippetConfig; | |
}); | ||
// let message = "Load Version 2 SDK instead to support IE"; // where to report this error? | ||
} | ||
if (appInsights.cr){ | ||
for (var i = 0; i < domains.length; i++){ | ||
if (targetSrc.indexOf(domains[i])){ | ||
siyuniu-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
domainRetryIndex = 0; | ||
break; | ||
} | ||
} | ||
const _handleError = (evt?: any) => { | ||
loadFailed = true; | ||
appInsights.queue = []; // Clear the queue | ||
if (!handled) { | ||
handled = true; | ||
_reportFailure(targetSrc); | ||
// start retry | ||
if (domainRetryIndex > 0 && domainRetryIndex < domains.length){ | ||
siyuniu-ms marked this conversation as resolved.
Show resolved
Hide resolved
|
||
theScript = _createScript("https://" + domains[domainRetryIndex] + "/scripts/b/ai.2.min.js"); | ||
} else { | ||
handled = true; | ||
loadFailed = true; | ||
_reportFailure(targetSrc); | ||
} | ||
} | ||
} | ||
|
||
|
@@ -213,11 +238,12 @@ declare var cfg:ISnippetConfig; | |
} | ||
}, 500); | ||
} | ||
loadFailed = false; | ||
} | ||
|
||
const _createScript = () => { | ||
const _createScript = (src: string) => { | ||
let scriptElement : HTMLElement = doc.createElement(scriptText); | ||
(scriptElement as any)["src"] = targetSrc; | ||
(scriptElement as any)["src"] = src; | ||
// Allocate Cross origin only if defined and available | ||
let crossOrigin = cfg[strCrossOrigin]; | ||
if ((crossOrigin || crossOrigin === "") && scriptElement[strCrossOrigin] != strUndefined) { | ||
|
@@ -235,7 +261,8 @@ declare var cfg:ISnippetConfig; | |
return scriptElement; | ||
} | ||
|
||
let theScript = _createScript(); | ||
let theScript = _createScript(targetSrc); | ||
|
||
if (cfg.ld && cfg.ld < 0) { | ||
// if user wants to append tag to document head, blocking page load | ||
let headNode = doc.getElementsByTagName("head")[0]; | ||
|
Oops, something went wrong.
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.
Once we have tested this, we will (I think) want this to be the default, so then if someone doesn't want to retry they would be required to set this to
false
and then we just changeif (appInsights.cr){
toif (appInsights.cr !== false){
so that anything other thenfalse
would cause the retry to occur.