Skip to content

Commit

Permalink
do not enable RUM agent when nodejs is run in contextPropagationOnly …
Browse files Browse the repository at this point in the history
…mode
  • Loading branch information
restrry committed Nov 16, 2021
1 parent f7344ef commit 1f72957
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 16 additions & 0 deletions src/core/server/http_resources/get_apm_config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ describe('getApmConfig', () => {
expect(getApmConfig('/path')).toBeNull();
});

it('returns null if apm is enabled with contextPropagationOnly: true', () => {
getConfigurationMock.mockReturnValue({
active: true,
contextPropagationOnly: true,
});
expect(getApmConfig('/path')).toBeDefined();
});

it('returns null if apm is enabled with disableSend: true', () => {
getConfigurationMock.mockReturnValue({
active: true,
disableSend: true,
});
expect(getApmConfig('/path')).toBeDefined();
});

it('calls `getConfig` with the correct parameters', () => {
getApmConfig('/path');

Expand Down
10 changes: 8 additions & 2 deletions src/core/server/http_resources/get_apm_config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@
* Side Public License, v 1.
*/

import agent from 'elastic-apm-node';
import agent, { AgentConfigOptions } from 'elastic-apm-node';
import { getConfiguration } from '@kbn/apm-config-loader';

function shouldInstrumentClient(config?: AgentConfigOptions): boolean {
return Boolean(
config?.active === true && config.contextPropagationOnly !== true && config.disableSend !== true
);
}

export const getApmConfig = (requestPath: string) => {
const baseConfig = getConfiguration('kibana-frontend');
if (!baseConfig?.active) {
if (!shouldInstrumentClient(baseConfig)) {
return null;
}

Expand Down

0 comments on commit 1f72957

Please sign in to comment.