Skip to content

Commit

Permalink
chore: refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
abhilash-sivan committed Aug 22, 2024
1 parent da796f2 commit e6f1af1
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 50 deletions.
10 changes: 7 additions & 3 deletions packages/core/src/tracing/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ const {
isESMApp
} = require('../util/esm');
const iitmHook = require('../util/iitmHook');
const { logPackageInstallation } = require('../util/logPackageInstallation');
const { getPackageInstallation } = require('../util/getPackageInstallation');

let tracingEnabled = false;
let tracingActivated = false;
Expand Down Expand Up @@ -180,8 +180,12 @@ exports.preInit = function preInit(preliminaryConfig) {
* @param {CollectorPIDStore} _processIdentityProvider
*/
exports.init = function init(_config, downstreamConnection, _processIdentityProvider) {
// Logs the instana instrumentation method of client application in debug mode
logPackageInstallation();
if (process.env.INSTANA_DEBUG || process.env.INSTANA_LOG_LEVEL === 'debug') {
const method = getPackageInstallation();

// eslint-disable-next-line no-console
console.debug(`The App has instrumented instana using: ${method}`);
}

// Consider removing this in the next major release(v4.x) of the @instana package.
if (hasExperimentalLoaderFlag()) {
Expand Down
37 changes: 37 additions & 0 deletions packages/core/src/util/getPackageInstallation.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* (c) Copyright IBM Corp. 2024
*/

'use strict';

const isESMApp = require('./esm').isESMApp;

exports.getPackageInstallation = function getPackageInstallation() {
const instrumentationMap = {
usingExperimentalLoaderFlag: '--experimental-loader flag',
usingImport: '--import flag',
usingRequire: '--require flag',
noFlags: 'no additional flags'
};
let method = '';

if (isESMApp()) {
const usingExperimentalLoaderFlag =
process.env.NODE_OPTIONS?.includes('--experimental-loader')
|| process.execArgv?.[0]?.includes('--experimental-loader')
? 'usingExperimentalLoaderFlag' : '';
const usingImportFlag =
process.env.NODE_OPTIONS?.includes('--import') || process.execArgv?.[0]?.includes('--import')
? 'usingImport' : '';
method = instrumentationMap[usingExperimentalLoaderFlag || usingImportFlag || 'noFlags'];
} else {
const usingRequire =
(process.env.NODE_OPTIONS?.includes('--require') && process.env.NODE_OPTIONS?.includes('@instana')) ||
(process.execArgv?.[0]?.includes('--require') && process.execArgv?.[0].includes('@instana')) ||
(process.execArgv?.[0]?.includes('--require') && process.execArgv?.[1].includes('@instana'))
? 'usingRequire' : '';
method = instrumentationMap[usingRequire || 'noFlags'];
}

return method;
};
47 changes: 0 additions & 47 deletions packages/core/src/util/logPackageInstallation.js

This file was deleted.

0 comments on commit e6f1af1

Please sign in to comment.