Skip to content
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

Update How Manual Attach is Checked #1286

Merged
merged 4 commits into from
Feb 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Bootstrap/Default.ts
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Loading