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 SDK Already Attached Check #1334

Merged
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
67 changes: 34 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions src/agent/agentLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,34 +241,34 @@ export class AgentLoader {
try {
// appInstance should either resolve to user SDK or crash. If it resolves to attach SDK, user probably modified their NODE_PATH
let shimInstance: string;
let distroInstance: string;
let exporterInstance: string;
try {
// Node 8.9+ Windows
if (this._isWindows) {
shimInstance = (require.resolve as any)("applicationinsights", { paths: [process.cwd()] });
distroInstance = (require.resolve as any)("@azure/monitor-opentelemetry", { paths: [process.cwd()] });
exporterInstance = (require.resolve as any)("@azure/monitor-opentelemetry-exporter", { paths: [process.cwd()] });
}
// Node 8.9+ Linux
else if (this._isLinux) {
shimInstance = `${process.cwd()}${(require.resolve as any)("applicationinsights", { paths: [process.cwd()] })}`;
distroInstance = `${process.cwd()}${(require.resolve as any)("@azure/monitor-opentelemetry", { paths: [process.cwd()] })}`;
exporterInstance = `${process.cwd()}${(require.resolve as any)("@azure/monitor-opentelemetry-exporter", { paths: [process.cwd()] })}`;
}
} catch (e) {
// Node <8.9
shimInstance = require.resolve(`${process.cwd()}/node_modules/applicationinsights`);
distroInstance = require.resolve(`${process.cwd()}/node_modules/@azure/monitor-opentelemetry`);
exporterInstance = require.resolve(`${process.cwd()}/node_modules/@azure/monitor-opentelemetry-exporter`);
}
/**
* If loaded instance is in Azure machine home path do not attach the SDK, this means customer already instrumented their app.
* Linux App Service doesn't append the full cwd to the require.resolve, so we need to check for the relative path we expect
* if application insights is being imported in the user app code.
*/
if (
shimInstance.indexOf("home") > -1 || distroInstance.indexOf("home") > -1 ||
shimInstance.indexOf("home") > -1 || exporterInstance.indexOf("home") > -1 ||
(shimInstance === LINUX_USER_APPLICATION_INSIGHTS_PATH && this._isLinux)
) {
const diagnosticLog: IDiagnosticLog = {
message: `Azure Monitor Distro or Application Insights already exists. Module is already installed in this application; not re-attaching. Location: ${shimInstance}`,
message: `Azure Monitor Distro, Exporter, or Application Insights already exists. Module is already installed in this application; not re-attaching. Location: ${shimInstance}`,
messageId: DiagnosticMessageId.sdkExists
};
this._diagnosticLogger.logMessage(diagnosticLog);
Expand Down
Loading