Skip to content

Commit

Permalink
Add initialization from previously set values.
Browse files Browse the repository at this point in the history
Also address CodeQL issues
  • Loading branch information
MSNev committed May 31, 2022
1 parent 562a00e commit 6ea3d15
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common/publish/AzureStorageHelper/AzureStorageHelper.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ Function Get-VersionDetails (
Function Get-FileVersion (
[string] $name
) {
$regMatch = '^(.*\/)*([^\/\d]*\.)(\d+(\.\d+)*(-[\w\d\-\+]+\.?[\d\-\+]*)?)(\.(?:gbl\.js|gbl\.min\.js|cjs\.js|cjs\.min\.js|js|min\.js|integrity\.json|zip)(?:\.map)?)$'
$regMatch = '^(.*\/)*([^\/\d]*\.)(\d+(\.\d+)*(-[\w\d\-\+]+\.?[\w\d\-\+]*)?)(\.(?:gbl\.js|gbl\.min\.js|cjs\.js|cjs\.min\.js|js|min\.js|integrity\.json|zip)(?:\.map)?)$'
$match = ($name | select-string $regMatch -AllMatches).matches
$contentType = $jsContentType

Expand Down
4 changes: 2 additions & 2 deletions extensions/applicationinsights-dependencies-js/src/ajax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
IAppInsightsCore, BaseTelemetryPlugin, ITelemetryPluginChain, IConfiguration, IPlugin, ITelemetryItem, IProcessTelemetryContext,
getLocation, getGlobal, strPrototype, IInstrumentCallDetails, InstrumentFunc, InstrumentProto, getPerformance,
IInstrumentHooksCallbacks, objForEachKey, generateW3CId, getIEVersion, dumpObj, ICustomProperties, isXhrSupported, eventOn,
mergeEvtNamespace, createUniqueNamespace, createProcessTelemetryContext, _throwInternal, IDistributedTraceContext, getExceptionName, IDiagnosticLogger
mergeEvtNamespace, createUniqueNamespace, createProcessTelemetryContext, _throwInternal, IDistributedTraceContext, getExceptionName,
} from "@microsoft/applicationinsights-core-js";
import { ajaxRecord, IAjaxRecordResponse } from "./ajaxRecord";
import dynamicProto from "@microsoft/dynamicproto-js";
Expand Down Expand Up @@ -446,7 +446,7 @@ export class AjaxMonitor extends BaseTelemetryPlugin implements IDependenciesPlu
_disableAjaxTracking = false;
_disableFetchTracking = false;

_excludeRequestFromAutoTrackingPatterns = null
_excludeRequestFromAutoTrackingPatterns = null;
_addRequestContext = null;
_evtNamespace = null;
_dependencyListenerId = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ export class TelemetryTrace implements ITelemetryTrace {
const _self = this;
_self.traceID = id || generateW3CId();
_self.parentID = parentId;
_self.name = name;
let location = getLocation();
if (!name && location && location.pathname) {
_self.name = location.pathname;
name = location.pathname;
}

_self.name = dataSanitizeString(logger, _self.name);
_self.name = dataSanitizeString(logger, name);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ import dynamicProto from "@microsoft/dynamicproto-js";
import {
BaseTelemetryPlugin, IConfiguration, isNullOrUndefined,
IAppInsightsCore, IPlugin, ITelemetryItem, IProcessTelemetryContext, _InternalLogMessage, eLoggingSeverity, _eInternalMessageId, getNavigator,
ITelemetryPluginChain, objForEachKey, getSetValue, _logInternalMessage, IProcessTelemetryUnloadContext, ITelemetryUnloadState, isFunction, IDistributedTraceContext, ILoadedPlugin
ITelemetryPluginChain, objForEachKey, getSetValue, _logInternalMessage, IProcessTelemetryUnloadContext, ITelemetryUnloadState, IDistributedTraceContext
} from "@microsoft/applicationinsights-core-js";
import { TelemetryContext } from "./TelemetryContext";
import { PageView, IConfig, BreezeChannelIdentifier, PropertiesPluginIdentifier, IPropertiesPlugin, getExtensionByName, createDistributedTraceContextFromTrace } from "@microsoft/applicationinsights-common";
import { PageView, IConfig, BreezeChannelIdentifier, PropertiesPluginIdentifier, IPropertiesPlugin, createDistributedTraceContextFromTrace } from "@microsoft/applicationinsights-common";
import { ITelemetryConfig } from "./Interfaces/ITelemetryConfig";
import { IPropTelemetryContext } from "./Interfaces/IPropTelemetryContext";

Expand Down Expand Up @@ -64,8 +64,8 @@ export default class PropertiesPlugin extends BaseTelemetryPlugin implements IPr
_extensionConfig[field] = () => ctx.getConfig(identifier, field, value() as any);
});

_self.context = new TelemetryContext(core, _extensionConfig);
_previousTraceCtx = core.getTraceCtx(false);
_self.context = new TelemetryContext(core, _extensionConfig, _previousTraceCtx);
_distributedTraceCtx = createDistributedTraceContextFromTrace(_self.context.telemetryTrace, _previousTraceCtx);
core.setTraceCtx(_distributedTraceCtx);
_self.context.appId = () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

import dynamicProto from "@microsoft/dynamicproto-js";
import { ITelemetryItem, IProcessTelemetryContext, IAppInsightsCore, isString, objKeys, hasWindow, _InternalLogMessage, setValue, getSetValue } from "@microsoft/applicationinsights-core-js";
import { ITelemetryItem, IProcessTelemetryContext, IAppInsightsCore, isString, objKeys, hasWindow, _InternalLogMessage, setValue, getSetValue, IDistributedTraceContext } from "@microsoft/applicationinsights-core-js";
import { Session, _SessionManager } from "./Context/Session";
import { Extensions, IOperatingSystem, ITelemetryTrace, IWeb, CtxTagKeys, PageView, IApplication, IDevice, ILocation, IUserContext, IInternal, ISession } from "@microsoft/applicationinsights-common";
import { Application } from "./Context/Application";
Expand Down Expand Up @@ -40,7 +40,7 @@ export class TelemetryContext implements IPropTelemetryContext {
public appId: () => string;
public getSessionId: () => string;

constructor(core: IAppInsightsCore, defaultConfig: ITelemetryConfig) {
constructor(core: IAppInsightsCore, defaultConfig: ITelemetryConfig, previousTraceCtx?: IDistributedTraceContext) {
let logger = core.logger
this.appId = () => null;
this.getSessionId = () => null;
Expand All @@ -53,7 +53,16 @@ export class TelemetryContext implements IPropTelemetryContext {
_self.device = new Device();
_self.location = new Location();
_self.user = new User(defaultConfig, core);
_self.telemetryTrace = new TelemetryTrace(undefined, undefined, undefined, logger);

let traceId: string;
let parentId: string;
let name: string;
if (previousTraceCtx) {
traceId = previousTraceCtx.getTraceId();
parentId = previousTraceCtx.getSpanId();
name = previousTraceCtx.getName();
}
_self.telemetryTrace = new TelemetryTrace(traceId, parentId, name, logger);
_self.session = new Session();
}

Expand Down
2 changes: 1 addition & 1 deletion shared/AppInsightsCore/src/JavaScriptSDK/W3cTraceParent.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ITraceParent } from "../JavaScriptSDK.Interfaces/ITraceParent";
import { generateW3CId } from "./CoreUtils";
import { findMetaTag, findNamedServerTiming, getDocument, getPerformance } from "./EnvUtils";
import { findMetaTag, findNamedServerTiming } from "./EnvUtils";
import { isArray, isString, strTrim } from "./HelperFuncs";

// using {0,16} for leading and trailing whitespace just to constrain the possible runtime of a random string
Expand Down

0 comments on commit 6ea3d15

Please sign in to comment.