[main] [BUG] using EndPointUrl (and IngestionEndpoint) results in Telemetry sent to incorrect urls #2197 (#2274)
This commit is contained in:
Родитель
a20e6891a1
Коммит
8281dc5333
|
@ -140,6 +140,7 @@ export class ApplicationInsightsTests extends AITestClass {
|
|||
this.addAsyncTests();
|
||||
this.addDependencyPluginTests();
|
||||
this.addPropertiesPluginTests();
|
||||
this.addCDNOverrideTests();
|
||||
}
|
||||
|
||||
public addGenericE2ETests(): void {
|
||||
|
@ -241,6 +242,22 @@ export class ApplicationInsightsTests extends AITestClass {
|
|||
});
|
||||
}
|
||||
|
||||
public addCDNOverrideTests(): void {
|
||||
this.testCase({
|
||||
name: 'CDNOverrideTests: customer could overwrite the url endpoint',
|
||||
useFakeTimers: true,
|
||||
test: () => {
|
||||
let ingestionendpoint = "https://dc.services.visualstudio.com";
|
||||
this._ai.config.connectionString = "InstrumentationKey=xxx;IngestionEndpoint=" + ingestionendpoint + ";LiveEndpoint=https://eastus.livediagnostics.monitor.azure.com/"
|
||||
this.clock.tick(100);
|
||||
Assert.deepEqual(this._ai.config.endpointUrl, ingestionendpoint + "/v2/track", "endpoint url is set from connection string");
|
||||
this._ai.config.userOverrideEndpointUrl = "https://custom.endpoint";
|
||||
this.clock.tick(100);
|
||||
Assert.deepEqual(this._ai.config.endpointUrl, this._ai.config.userOverrideEndpointUrl, "endpoint url is override by userOverrideEndpointUrl");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public addAnalyticsApiTests(): void {
|
||||
this.testCase({
|
||||
name: 'E2E.AnalyticsApiTests: Public Members exist',
|
||||
|
|
|
@ -18,6 +18,7 @@ export function createSnippetV5(snipConfig) {
|
|||
var scriptText = "script";
|
||||
var strInstrumentationKey = "instrumentationKey";
|
||||
var strIngestionendpoint = "ingestionendpoint";
|
||||
var userOverrideEndpointUrl = "userOverrideEndpointUrl";
|
||||
var strDisableExceptionTracking = "disableExceptionTracking";
|
||||
var strAiDevice = "ai.device.";
|
||||
var strAiOperationName = "ai.operation.name";
|
||||
|
@ -89,8 +90,7 @@ export function createSnippetV5(snipConfig) {
|
|||
var conString = _parseConnectionString();
|
||||
var iKey = conString[strInstrumentationKey] || aiConfig[strInstrumentationKey] || strEmpty;
|
||||
var ingest = conString[strIngestionendpoint];
|
||||
var endpointUrl = ingest ? ingest + "/v2/track" : aiConfig.endpointUrl; // only add /v2/track when from connectionstring
|
||||
|
||||
var endpointUrl = aiConfig[userOverrideEndpointUrl] ? aiConfig[userOverrideEndpointUrl] : (ingest + "/v2/track");
|
||||
var message = "SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)";
|
||||
var evts = [];
|
||||
evts.push(_createException(iKey, message, targetSrc, endpointUrl));
|
||||
|
|
|
@ -18,6 +18,7 @@ export function createSnippetV6(snipConfig) {
|
|||
var scriptText = "script";
|
||||
var strInstrumentationKey = "instrumentationKey";
|
||||
var strIngestionendpoint = "ingestionendpoint";
|
||||
var userOverrideEndpointUrl = "userOverrideEndpointUrl";
|
||||
var strDisableExceptionTracking = "disableExceptionTracking";
|
||||
var strAiDevice = "ai.device.";
|
||||
var strAiOperationName = "ai.operation.name";
|
||||
|
@ -90,7 +91,7 @@ export function createSnippetV6(snipConfig) {
|
|||
var conString = _parseConnectionString();
|
||||
var iKey = conString[strConStringIKey] || aiConfig[strInstrumentationKey] || strEmpty;
|
||||
var ingest = conString[strIngestionendpoint];
|
||||
var endpointUrl = ingest ? ingest + "/v2/track" : aiConfig.endpointUrl; // only add /v2/track when from connectionstring
|
||||
var endpointUrl = aiConfig[userOverrideEndpointUrl] ? aiConfig[userOverrideEndpointUrl] : (ingest + "/v2/track");
|
||||
|
||||
var message = "SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)";
|
||||
var evts = [];
|
||||
|
|
|
@ -75,6 +75,7 @@ const defaultConfigValues: IConfigDefaults<IConfiguration|IConfig> = {
|
|||
connectionString: UNDEFINED_VALUE,
|
||||
endpointUrl: UNDEFINED_VALUE,
|
||||
instrumentationKey: UNDEFINED_VALUE,
|
||||
userOverrideEndpointUrl: UNDEFINED_VALUE,
|
||||
diagnosticLogInterval: cfgDfValidate(_chkDiagLevel, 10000),
|
||||
featureOptIn:{
|
||||
[IKEY_USAGE]: {mode: FeatureOptInMode.disable},
|
||||
|
@ -196,9 +197,11 @@ export class AppInsightsSku implements IApplicationInsights {
|
|||
if (_config.connectionString) {
|
||||
const cs = parseConnectionString(_config.connectionString);
|
||||
const ingest = cs.ingestionendpoint;
|
||||
_config.endpointUrl = ingest ? (ingest + DEFAULT_BREEZE_PATH) : _config.endpointUrl; // only add /v2/track when from connectionstring
|
||||
_config.endpointUrl = _config.userOverrideEndpointUrl ? _config.userOverrideEndpointUrl : ingest + DEFAULT_BREEZE_PATH; // add /v2/track
|
||||
_config.instrumentationKey = cs.instrumentationkey || _config.instrumentationKey;
|
||||
}
|
||||
// userOverrideEndpointUrl have the highest priority
|
||||
_config.endpointUrl = _config.userOverrideEndpointUrl ? _config.userOverrideEndpointUrl : _config.endpointUrl;
|
||||
}));
|
||||
|
||||
_self.snippet = snippet;
|
||||
|
|
|
@ -76,9 +76,11 @@ export class ApplicationInsights {
|
|||
if (_config.connectionString) {
|
||||
const cs = parseConnectionString(_config.connectionString);
|
||||
const ingest = cs.ingestionendpoint;
|
||||
_config.endpointUrl = ingest ? (ingest + DEFAULT_BREEZE_PATH) : _config.endpointUrl; // only add /v2/track when from connectionstring
|
||||
_config.endpointUrl = _config.userOverrideEndpointUrl ? _config.userOverrideEndpointUrl : (ingest + DEFAULT_BREEZE_PATH); // only add /v2/track when from connectionstring
|
||||
_config.instrumentationKey = cs.instrumentationkey || _config.instrumentationKey;
|
||||
}
|
||||
// userOverrideEndpointUrl have the highest priority
|
||||
_config.endpointUrl = _config.userOverrideEndpointUrl ? _config.userOverrideEndpointUrl : _config.endpointUrl;
|
||||
}));
|
||||
|
||||
// initialize core
|
||||
|
|
|
@ -30,12 +30,12 @@ export function parseConnectionString(connectionString?: string): ConnectionStri
|
|||
// this is a valid connection string, so parse the results
|
||||
|
||||
if (result.endpointsuffix) {
|
||||
// use endpoint suffix where overrides are not provided
|
||||
// apply the default endpoints
|
||||
const locationPrefix = result.location ? result.location + "." : "";
|
||||
result.ingestionendpoint = result.ingestionendpoint || ("https://" + locationPrefix + "dc." + result.endpointsuffix);
|
||||
}
|
||||
|
||||
// apply the default endpoints
|
||||
// apply user override endpoint or the default endpoints
|
||||
result.ingestionendpoint = result.ingestionendpoint || DEFAULT_BREEZE_ENDPOINT;
|
||||
|
||||
if (strEndsWith(result.ingestionendpoint, "/")) {
|
||||
|
|
|
@ -383,6 +383,12 @@ export interface IConfig {
|
|||
* [Optional] Sets throttle mgr configuration by key
|
||||
*/
|
||||
throttleMgrCfg?: {[key: number]: IThrottleMgrConfig};
|
||||
|
||||
/**
|
||||
* [Optional] Specifies a Highest Priority custom endpoint URL where telemetry data will be sent.
|
||||
* This URL takes precedence over the 'config.endpointUrl' and any endpoint in the connection string.
|
||||
*/
|
||||
userOverrideEndpointUrl?: string;
|
||||
}
|
||||
|
||||
export class ConfigurationManager {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import { Fields, ISnippetConfig } from "./type";
|
||||
import { IEnvelope } from "@microsoft/applicationinsights-common";
|
||||
import { IConfig, IEnvelope } from "@microsoft/applicationinsights-common";
|
||||
import { IConfiguration, Snippet } from "@microsoft/applicationinsights-web";
|
||||
|
||||
// To ensure that SnippetConfig resides at the bottom of snippet.min.js,
|
||||
|
@ -32,7 +32,7 @@ declare var cfg:ISnippetConfig;
|
|||
// Only set if supplied or another name is defined to avoid polluting the global namespace
|
||||
win[sdkInstanceName] = aiName;
|
||||
}
|
||||
let aiSdk = win[aiName] || (function (aiConfig: IConfiguration) {
|
||||
let aiSdk = win[aiName] || (function (aiConfig: IConfiguration & IConfig) {
|
||||
let loadFailed = false;
|
||||
let handled = false;
|
||||
let appInsights: (Snippet & {initialize:boolean, cookie?:any, core?:any})= {
|
||||
|
@ -103,6 +103,7 @@ declare var cfg:ISnippetConfig;
|
|||
ingest = ingest.slice(0,-1);
|
||||
}
|
||||
let endpointUrl = ingest ? ingest + "/v2/track" : aiConfig.endpointUrl; // only add /v2/track when from connectionstring
|
||||
endpointUrl = aiConfig.userOverrideEndpointUrl ? aiConfig.userOverrideEndpointUrl : endpointUrl;
|
||||
|
||||
let message = "SDK LOAD Failure: Failed to load Application Insights SDK script (See stack for details)";
|
||||
let evts:IEnvelope[] = [];
|
||||
|
|
Загрузка…
Ссылка в новой задаче