Skip to content

Commit

Permalink
Disable capturing of inproc dependencies in app insights (#724)
Browse files Browse the repository at this point in the history
Sentry was registering extra events against app insights
  • Loading branch information
andrewrlee authored Oct 8, 2024
1 parent bf88927 commit 119dbe0
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 0 deletions.
43 changes: 43 additions & 0 deletions server/utils/__tests__/azureInsights.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const { Contracts } = require('applicationinsights');
const {
addEstablishmentProcessor,
ignoreStaticAssetsProcessor,
ignoreInProcDependencies,
} = require('../azureAppInsights');

describe('azureAppInsights', () => {
Expand Down Expand Up @@ -111,4 +112,46 @@ describe('azureAppInsights', () => {
expect(result).toBe(false);
});
});

describe('ignoreInProcDependencies', () => {
const context = {};

const createRemoteDependencyData = type => {
const baseData = new Contracts.RemoteDependencyData();
baseData.name = 'name';
baseData.type = type;
return baseData;
};

const createEnvelope = baseData => ({
data: {
baseType: 'RemoteDependencyData',
baseData,
},
});

it('processes when missing request data', () => {
const envelope = createEnvelope(null);

const result = ignoreInProcDependencies(envelope, context);

expect(result).toBe(true);
});

it('processes when unknown baseType', () => {
const envelope = createEnvelope(createRemoteDependencyData('HTTP'));

const result = ignoreInProcDependencies(envelope, context);

expect(result).toBe(true);
});

it('does not InProc dependencies', () => {
const envelope = createEnvelope(createRemoteDependencyData('InProc'));

const result = ignoreInProcDependencies(envelope, context);

expect(result).toBe(false);
});
});
});
9 changes: 9 additions & 0 deletions server/utils/azureAppInsights.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ function ignoreStaticAssetsProcessor(envelope) {
return true;
}

function ignoreInProcDependencies(envelope) {
if (envelope.data.baseType === Contracts.TelemetryTypeString.Dependency) {
return envelope.data.baseData?.type !== 'InProc';
}
return true;
}

function addEstablishmentProcessor(envelope, contextObjects) {
if (envelope.data.baseType === Contracts.TelemetryTypeString.Request) {
const establishmentName =
Expand Down Expand Up @@ -49,11 +56,13 @@ function initialiseAppInsights() {
client.context.tags['ai.application.ver'] = version();
client.addTelemetryProcessor(addEstablishmentProcessor);
client.addTelemetryProcessor(ignoreStaticAssetsProcessor);
client.addTelemetryProcessor(ignoreInProcDependencies);
return client;
}

module.exports = {
ignoreStaticAssetsProcessor,
ignoreInProcDependencies,
addEstablishmentProcessor,
initialiseAppInsights,
};

0 comments on commit 119dbe0

Please sign in to comment.