Skip to content

Commit

Permalink
Update How Manual Attach is Checked (#1286)
Browse files Browse the repository at this point in the history
* Update how manual attach is checked.

* Update Default.ts
  • Loading branch information
JacksonWeber committed Feb 27, 2024
1 parent 1b53f5a commit 4d8d07e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions Bootstrap/Default.ts
Expand Up @@ -12,10 +12,10 @@ import Context = require("../Library/Context");

// Private configuration vars
let _appInsights: typeof types | null;
let _prefix = `${PrefixHelpers.getResourceProvider()}${PrefixHelpers.getOsPrefix()}${Constants.AttachTypePrefix.INTEGRATED_AUTO}_`;
let _fullSdkVersion = `${_prefix}node:${Context.sdkVersion}`;

export const defaultConfig = new Config(); // Will read env variables, expose for Agent initialization
let _prefix = `${PrefixHelpers.getResourceProvider()}${PrefixHelpers.getOsPrefix()}${Constants.AttachTypePrefix.INTEGRATED_AUTO}_`;
let _fullSdkVersion = `${_prefix}node:${Context.sdkVersion}`;
const _instrumentationKey = defaultConfig.instrumentationKey;
let _logger: DiagnosticLogger = new DiagnosticLogger(console, _instrumentationKey);
let _statusLogger: StatusLogger = new StatusLogger(console, _instrumentationKey);
Expand Down Expand Up @@ -111,6 +111,7 @@ export function setupAndStart(aadTokenCredential?: azureCoreAuth.TokenCredential
}

// Instrument the SDK
Context.sdkPrefix = _prefix;
_appInsights.setup();
const appInsightsSDKVersion = _appInsights.defaultClient.context.keys.internalSdkVersion;

Expand Down
7 changes: 3 additions & 4 deletions Library/Context.ts
Expand Up @@ -7,15 +7,15 @@ import { APPLICATION_INSIGHTS_SDK_VERSION } from "../Declarations/Constants";
import Logging = require("./Logging");
import * as PrefixHelpers from "./PrefixHelper";
import * as Constants from "../Declarations/Constants";
import appInsights = require("../Bootstrap/Oryx");

class Context {

public keys: Contracts.ContextTagKeys;
public tags: { [key: string]: string };
public static DefaultRoleName: string = "Web";
public static appVersion: { [path: string]: string } = {};
public static sdkVersion: string = null;
public static sdkVersion: string = APPLICATION_INSIGHTS_SDK_VERSION;
public static sdkPrefix: string = null;

constructor(packageJsonPath?: string) {
this.keys = new Contracts.ContextTagKeys();
Expand Down Expand Up @@ -67,9 +67,8 @@ class Context {
}

private _loadInternalContext() {
Context.sdkVersion = APPLICATION_INSIGHTS_SDK_VERSION;
// If Context is already set in the bootstrap, don't set it here
if (PrefixHelpers.getResourceProvider() === "u") {
if (!Context.sdkPrefix) {
this.tags[this.keys.internalSdkVersion] = `${PrefixHelpers.getResourceProvider()}${PrefixHelpers.getOsPrefix()}${Constants.AttachTypePrefix.MANUAL}_node:${Context.sdkVersion}`
}
}
Expand Down
2 changes: 2 additions & 0 deletions Tests/Library/Context.tests.ts
Expand Up @@ -18,6 +18,8 @@ describe("Library/Context", () => {
var jsonContent = JSON.stringify({ "version": "testVersion" });
var testFilePath = path.resolve(__dirname, "testpackage.json");
fs.writeFile(testFilePath, jsonContent, () => { });
// Clear the sdkPrefix in case it's been set by other tests initializing the agent.
Context.sdkPrefix = null;
});

after(() => {
Expand Down

0 comments on commit 4d8d07e

Please sign in to comment.