mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Update APM nodejs agent to v3.21.1 (#112504)
* bump apm agent to 3.21.0 * use types provided by APM agent * fix bazel build * bump version to 3.21.1 Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
20f4a9d12f
commit
382f27cf62
8 changed files with 34 additions and 61 deletions
|
@ -223,7 +223,7 @@
|
|||
"deep-freeze-strict": "^1.1.1",
|
||||
"deepmerge": "^4.2.2",
|
||||
"del": "^5.1.0",
|
||||
"elastic-apm-node": "^3.20.0",
|
||||
"elastic-apm-node": "^3.21.1",
|
||||
"execa": "^4.0.2",
|
||||
"exit-hook": "^2.2.0",
|
||||
"expiry-js": "0.1.7",
|
||||
|
|
|
@ -36,6 +36,7 @@ RUNTIME_DEPS = [
|
|||
TYPES_DEPS = [
|
||||
"//packages/elastic-safer-lodash-set",
|
||||
"//packages/kbn-utils",
|
||||
"@npm//elastic-apm-node",
|
||||
"@npm//@types/jest",
|
||||
"@npm//@types/js-yaml",
|
||||
"@npm//@types/lodash",
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { Labels } from 'elastic-apm-node';
|
||||
import {
|
||||
packageMock,
|
||||
mockedRootDir,
|
||||
|
@ -46,7 +46,8 @@ describe('ApmConfiguration', () => {
|
|||
it('sets the git revision from `git rev-parse` command in non distribution mode', () => {
|
||||
gitRevExecMock.mockReturnValue('some-git-rev');
|
||||
const config = new ApmConfiguration(mockedRootDir, {}, false);
|
||||
expect(config.getConfig('serviceName').globalLabels?.git_rev).toBe('some-git-rev');
|
||||
const labels = config.getConfig('serviceName').globalLabels as Labels;
|
||||
expect(labels.git_rev).toBe('some-git-rev');
|
||||
});
|
||||
|
||||
it('sets the git revision from `pkg.build.sha` in distribution mode', () => {
|
||||
|
@ -58,13 +59,15 @@ describe('ApmConfiguration', () => {
|
|||
},
|
||||
};
|
||||
const config = new ApmConfiguration(mockedRootDir, {}, true);
|
||||
expect(config.getConfig('serviceName').globalLabels?.git_rev).toBe('distribution-sha');
|
||||
const labels = config.getConfig('serviceName').globalLabels as Labels;
|
||||
expect(labels.git_rev).toBe('distribution-sha');
|
||||
});
|
||||
|
||||
it('reads the kibana uuid from the uuid file', () => {
|
||||
readUuidFileMock.mockReturnValue('instance-uuid');
|
||||
const config = new ApmConfiguration(mockedRootDir, {}, false);
|
||||
expect(config.getConfig('serviceName').globalLabels?.kibana_uuid).toBe('instance-uuid');
|
||||
const labels = config.getConfig('serviceName').globalLabels as Labels;
|
||||
expect(labels.kibana_uuid).toBe('instance-uuid');
|
||||
});
|
||||
|
||||
it('uses the uuid from the kibana config if present', () => {
|
||||
|
@ -75,7 +78,8 @@ describe('ApmConfiguration', () => {
|
|||
},
|
||||
};
|
||||
const config = new ApmConfiguration(mockedRootDir, kibanaConfig, false);
|
||||
expect(config.getConfig('serviceName').globalLabels?.kibana_uuid).toBe('uuid-from-config');
|
||||
const labels = config.getConfig('serviceName').globalLabels as Labels;
|
||||
expect(labels.kibana_uuid).toBe('uuid-from-config');
|
||||
});
|
||||
|
||||
it('overrides metricsInterval, breakdownMetrics, captureHeaders, and captureBody when `isDistributable` is true', () => {
|
||||
|
|
|
@ -12,17 +12,17 @@ import { execSync } from 'child_process';
|
|||
// deep import to avoid loading the whole package
|
||||
import { getDataPath } from '@kbn/utils';
|
||||
import { readFileSync } from 'fs';
|
||||
import { ApmAgentConfig } from './types';
|
||||
import type { AgentConfigOptions } from 'elastic-apm-node';
|
||||
|
||||
// https://www.elastic.co/guide/en/apm/agent/nodejs/current/configuration.html
|
||||
const DEFAULT_CONFIG: ApmAgentConfig = {
|
||||
const DEFAULT_CONFIG: AgentConfigOptions = {
|
||||
active: false,
|
||||
environment: 'development',
|
||||
logUncaughtExceptions: true,
|
||||
globalLabels: {},
|
||||
};
|
||||
|
||||
const CENTRALIZED_SERVICE_BASE_CONFIG: ApmAgentConfig = {
|
||||
const CENTRALIZED_SERVICE_BASE_CONFIG: AgentConfigOptions = {
|
||||
serverUrl: 'https://38b80fbd79fb4c91bae06b4642d4d093.apm.us-east-1.aws.cloud.es.io',
|
||||
|
||||
// The secretToken below is intended to be hardcoded in this file even though
|
||||
|
@ -39,7 +39,7 @@ const CENTRALIZED_SERVICE_BASE_CONFIG: ApmAgentConfig = {
|
|||
breakdownMetrics: true,
|
||||
};
|
||||
|
||||
const CENTRALIZED_SERVICE_DIST_CONFIG: ApmAgentConfig = {
|
||||
const CENTRALIZED_SERVICE_DIST_CONFIG: AgentConfigOptions = {
|
||||
metricsInterval: '120s',
|
||||
captureBody: 'off',
|
||||
captureHeaders: false,
|
||||
|
@ -47,7 +47,7 @@ const CENTRALIZED_SERVICE_DIST_CONFIG: ApmAgentConfig = {
|
|||
};
|
||||
|
||||
export class ApmConfiguration {
|
||||
private baseConfig?: ApmAgentConfig;
|
||||
private baseConfig?: AgentConfigOptions;
|
||||
private kibanaVersion: string;
|
||||
private pkgBuild: Record<string, any>;
|
||||
|
||||
|
@ -62,7 +62,7 @@ export class ApmConfiguration {
|
|||
this.pkgBuild = build;
|
||||
}
|
||||
|
||||
public getConfig(serviceName: string): ApmAgentConfig {
|
||||
public getConfig(serviceName: string): AgentConfigOptions {
|
||||
return {
|
||||
...this.getBaseConfig(),
|
||||
serviceName,
|
||||
|
@ -107,8 +107,8 @@ export class ApmConfiguration {
|
|||
/**
|
||||
* Override some config values when specific environment variables are used
|
||||
*/
|
||||
private getConfigFromEnv(): ApmAgentConfig {
|
||||
const config: ApmAgentConfig = {};
|
||||
private getConfigFromEnv(): AgentConfigOptions {
|
||||
const config: AgentConfigOptions = {};
|
||||
|
||||
if (process.env.ELASTIC_APM_ACTIVE === 'true') {
|
||||
config.active = true;
|
||||
|
@ -142,7 +142,7 @@ export class ApmConfiguration {
|
|||
* Get the elastic.apm configuration from the --config file, supersedes the
|
||||
* default config.
|
||||
*/
|
||||
private getConfigFromKibanaConfig(): ApmAgentConfig {
|
||||
private getConfigFromKibanaConfig(): AgentConfigOptions {
|
||||
return this.rawKibanaConfig?.elastic?.apm ?? {};
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ export class ApmConfiguration {
|
|||
* Get the configuration from the apm.dev.js file, supersedes config
|
||||
* from the --config file, disabled when running the distributable
|
||||
*/
|
||||
private getDevConfig(): ApmAgentConfig {
|
||||
private getDevConfig(): AgentConfigOptions {
|
||||
if (this.isDistributable) {
|
||||
return {};
|
||||
}
|
||||
|
@ -167,7 +167,7 @@ export class ApmConfiguration {
|
|||
* Determine the Kibana UUID, initialized the value of `globalLabels.kibana_uuid`
|
||||
* when the UUID can be determined.
|
||||
*/
|
||||
private getUuidConfig(): ApmAgentConfig {
|
||||
private getUuidConfig(): AgentConfigOptions {
|
||||
// try to access the `server.uuid` value from the config file first.
|
||||
// if not manually defined, we will then read the value from the `{DATA_FOLDER}/uuid` file.
|
||||
// note that as the file is created by the platform AFTER apm init, the file
|
||||
|
@ -207,7 +207,7 @@ export class ApmConfiguration {
|
|||
* When running Kibana with ELASTIC_APM_ENVIRONMENT=ci we attempt to grab
|
||||
* some environment variables we populate in CI related to the build under test
|
||||
*/
|
||||
private getCiConfig(): ApmAgentConfig {
|
||||
private getCiConfig(): AgentConfigOptions {
|
||||
if (process.env.ELASTIC_APM_ENVIRONMENT !== 'ci') {
|
||||
return {};
|
||||
}
|
||||
|
|
|
@ -5,10 +5,9 @@
|
|||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
import type { AgentConfigOptions } from 'elastic-apm-node';
|
||||
import { getConfigurationFilePaths, getConfigFromFiles, applyConfigOverrides } from './utils';
|
||||
import { ApmConfiguration } from './config';
|
||||
import { ApmAgentConfig } from './types';
|
||||
|
||||
let apmConfig: ApmConfiguration | undefined;
|
||||
|
||||
|
@ -32,7 +31,7 @@ export const loadConfiguration = (
|
|||
return apmConfig;
|
||||
};
|
||||
|
||||
export const getConfiguration = (serviceName: string): ApmAgentConfig | undefined => {
|
||||
export const getConfiguration = (serviceName: string): AgentConfigOptions | undefined => {
|
||||
// integration test runner starts a kibana server that import the module without initializing APM.
|
||||
// so we need to check initialization of the config.
|
||||
// note that we can't just load the configuration during this module's import
|
||||
|
|
|
@ -9,4 +9,3 @@
|
|||
export { getConfiguration } from './config_loader';
|
||||
export { initApm } from './init_apm';
|
||||
export type { ApmConfiguration } from './config';
|
||||
export type { ApmAgentConfig } from './types';
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
/*
|
||||
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
|
||||
* or more contributor license agreements. Licensed under the Elastic License
|
||||
* 2.0 and the Server Side Public License, v 1; you may not use this file except
|
||||
* in compliance with, at your election, the Elastic License 2.0 or the Server
|
||||
* Side Public License, v 1.
|
||||
*/
|
||||
|
||||
// There is an (incomplete) `AgentConfigOptions` type declared in node_modules/elastic-apm-node/index.d.ts
|
||||
// but it's not exported, and using ts tricks to retrieve the type via Parameters<ApmAgent['start']>[0]
|
||||
// causes errors in the generated .d.ts file because of esModuleInterop and the fact that the apm module
|
||||
// is just exporting an instance of the `ApmAgent` type.
|
||||
export interface ApmAgentConfig {
|
||||
active?: boolean;
|
||||
environment?: string;
|
||||
serviceName?: string;
|
||||
serviceVersion?: string;
|
||||
serverUrl?: string;
|
||||
secretToken?: string;
|
||||
logUncaughtExceptions?: boolean;
|
||||
globalLabels?: Record<string, string | boolean>;
|
||||
centralConfig?: boolean;
|
||||
metricsInterval?: string;
|
||||
captureSpanStackTraces?: boolean;
|
||||
transactionSampleRate?: number;
|
||||
breakdownMetrics?: boolean;
|
||||
captureHeaders?: boolean;
|
||||
captureBody?: 'off' | 'all' | 'errors' | 'transactions';
|
||||
}
|
19
yarn.lock
19
yarn.lock
|
@ -12215,10 +12215,10 @@ ejs@^3.1.2, ejs@^3.1.6:
|
|||
dependencies:
|
||||
jake "^10.6.1"
|
||||
|
||||
elastic-apm-http-client@^9.8.1:
|
||||
version "9.8.1"
|
||||
resolved "https://registry.yarnpkg.com/elastic-apm-http-client/-/elastic-apm-http-client-9.8.1.tgz#62a0352849e2d7a75696a1c777ad90ddb55083b0"
|
||||
integrity sha512-tVU7+y4nSDUEZp/TXbXDxE+kXbWHsGVG1umk0OOV71UEPc/AqC7xSP5ACirOlDkewkfCOFXkvNThgu2zlx8PUw==
|
||||
elastic-apm-http-client@^10.0.0:
|
||||
version "10.0.0"
|
||||
resolved "https://registry.yarnpkg.com/elastic-apm-http-client/-/elastic-apm-http-client-10.0.0.tgz#495651716c13a744544c4dc983107a948418d213"
|
||||
integrity sha512-D0Frzaqo2h6RxrbxkwfTZSu7tKkmmP3UGYLCp2Fq25cGT/3px4hBWvTc+nV7iDwj2rwdQl7CNkcathYNkyHRWQ==
|
||||
dependencies:
|
||||
breadth-filter "^2.0.0"
|
||||
container-info "^1.0.1"
|
||||
|
@ -12228,12 +12228,11 @@ elastic-apm-http-client@^9.8.1:
|
|||
object-filter-sequence "^1.0.0"
|
||||
readable-stream "^3.4.0"
|
||||
stream-chopper "^3.0.1"
|
||||
unicode-byte-truncate "^1.0.0"
|
||||
|
||||
elastic-apm-node@^3.20.0:
|
||||
version "3.20.0"
|
||||
resolved "https://registry.yarnpkg.com/elastic-apm-node/-/elastic-apm-node-3.20.0.tgz#c2f3c90a779d8580cceba292c22dad17ff859749"
|
||||
integrity sha512-oaUrj3IrtCUg3kzQnoFClw210OpXaCFzIdMO3EnY7z7+zHcjd5fLEMDHQ64qFzKeMt3aPrLBu6ou0HwuUe48Eg==
|
||||
elastic-apm-node@^3.21.1:
|
||||
version "3.21.1"
|
||||
resolved "https://registry.yarnpkg.com/elastic-apm-node/-/elastic-apm-node-3.21.1.tgz#5f79cfc6ba60469e4ec83d176b3d28ddee78b530"
|
||||
integrity sha512-qnYWvWXQx00pS98IFYxkRQ9+T+R8oh0KdsbCU8t1ouSozZI6l5frlwC9CVpsqakPnAuvWP/qIYJEKF3CkYPv0w==
|
||||
dependencies:
|
||||
"@elastic/ecs-pino-format" "^1.2.0"
|
||||
after-all-results "^2.0.0"
|
||||
|
@ -12242,7 +12241,7 @@ elastic-apm-node@^3.20.0:
|
|||
basic-auth "^2.0.1"
|
||||
cookie "^0.4.0"
|
||||
core-util-is "^1.0.2"
|
||||
elastic-apm-http-client "^9.8.1"
|
||||
elastic-apm-http-client "^10.0.0"
|
||||
end-of-stream "^1.4.4"
|
||||
error-callsites "^2.0.4"
|
||||
error-stack-parser "^2.0.6"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue