diff --git a/docs/configuration.asciidoc b/docs/configuration.asciidoc index 9fd9f2d1805..9a3397f5bda 100644 --- a/docs/configuration.asciidoc +++ b/docs/configuration.asciidoc @@ -72,7 +72,7 @@ WARNING: The API key is sent as plain-text in every request to the server, so yo ==== `serverUrl` * *Type:* String -* *Default:* `http://localhost:8200` +* *Default:* `http://127.0.0.1:8200` * *Env:* `ELASTIC_APM_SERVER_URL` The URL to where the APM Server is deployed. @@ -1146,7 +1146,7 @@ module.exports = { // Use if APM Server requires a token secretToken: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '' } ---- diff --git a/docs/custom-stack.asciidoc b/docs/custom-stack.asciidoc index d8b1d0c783e..52f97fd6a37 100644 --- a/docs/custom-stack.asciidoc +++ b/docs/custom-stack.asciidoc @@ -51,7 +51,7 @@ var apm = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) ---- diff --git a/docs/express.asciidoc b/docs/express.asciidoc index 564853e5481..a4693529c8f 100644 --- a/docs/express.asciidoc +++ b/docs/express.asciidoc @@ -49,7 +49,7 @@ const apm = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) diff --git a/docs/fastify.asciidoc b/docs/fastify.asciidoc index 0e5e9f26df7..fd322a49e55 100644 --- a/docs/fastify.asciidoc +++ b/docs/fastify.asciidoc @@ -50,7 +50,7 @@ var apm = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) diff --git a/docs/hapi.asciidoc b/docs/hapi.asciidoc index fc263fbb9db..06b70ce7ec8 100644 --- a/docs/hapi.asciidoc +++ b/docs/hapi.asciidoc @@ -46,7 +46,7 @@ const apm = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) diff --git a/docs/koa.asciidoc b/docs/koa.asciidoc index f963ab1e374..6153c4b4847 100644 --- a/docs/koa.asciidoc +++ b/docs/koa.asciidoc @@ -54,7 +54,7 @@ const apm = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) diff --git a/docs/opentracing.asciidoc b/docs/opentracing.asciidoc index 3972b0e9e9d..a59c06b9725 100644 --- a/docs/opentracing.asciidoc +++ b/docs/opentracing.asciidoc @@ -75,7 +75,7 @@ const agent = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) diff --git a/docs/restify.asciidoc b/docs/restify.asciidoc index 341b80abcc2..bbc7b4b8456 100644 --- a/docs/restify.asciidoc +++ b/docs/restify.asciidoc @@ -46,7 +46,7 @@ const apm = require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', }) diff --git a/docs/setup.asciidoc b/docs/setup.asciidoc index 907e713b0c5..e595ebb2b47 100644 --- a/docs/setup.asciidoc +++ b/docs/setup.asciidoc @@ -70,7 +70,7 @@ require('elastic-apm-node').start({ // Use if APM Server uses API keys for authentication apiKey: '', - // Set custom APM Server URL (default: http://localhost:8200) + // Set custom APM Server URL (default: http://127.0.0.1:8200) serverUrl: '', // Only activate the agent if it's running in production diff --git a/lib/agent.js b/lib/agent.js index c9df001974c..c7cf72512b4 100644 --- a/lib/agent.js +++ b/lib/agent.js @@ -198,15 +198,6 @@ Agent.prototype.setSpanOutcome = function (outcome) { Agent.prototype._config = function (opts) { this._conf = config.createConfig(opts, this.logger) this.logger = this._conf.logger - - const { host, port, protocol } = this._conf.serverUrl - ? parsers.parseUrl(this._conf.serverUrl) - : { host: 'localhost:8200', port: '8200' } - - this._conf.serverHost = host - this._conf.serverPort = port === '' - ? (protocol === 'https:' ? 443 : 80) - : parseInt(port, 10) } Agent.prototype.isStarted = function () { @@ -225,6 +216,7 @@ Agent.prototype.start = function (opts) { this.addFilter(require('./filters/http-headers')) } + // Check cases where we do *not* start. if (!this._conf.active) { this.logger.debug('Elastic APM agent disabled (`active` is false)') return this @@ -232,11 +224,19 @@ Agent.prototype.start = function (opts) { this.logger.error('Elastic APM is incorrectly configured: Missing serviceName (APM will be disabled)') this._conf.active = false return this - } else if (!(this._conf.serverPort >= 1 && this._conf.serverPort <= 65535)) { + } + // Sanity check the port from `serverUrl`. + const parsedUrl = parsers.parseUrl(this._conf.serverUrl) + const serverPort = (parsedUrl.port + ? Number(parsedUrl.port) + : (parsedUrl.protocol === 'https:' ? 443 : 80)) + if (!(serverPort >= 1 && serverPort <= 65535)) { this.logger.error('Elastic APM is incorrectly configured: serverUrl "%s" contains an invalid port! (allowed: 1-65535)', this._conf.serverUrl) this._conf.active = false return this - } else if (this._conf.logLevel === 'trace') { + } + + if (this._conf.logLevel === 'trace') { var stackObj = {} Error.captureStackTrace(stackObj) diff --git a/lib/config.js b/lib/config.js index dd03f925c62..d2423230218 100644 --- a/lib/config.js +++ b/lib/config.js @@ -90,6 +90,7 @@ var DEFAULTS = { ], serviceNodeName: undefined, serverTimeout: '30s', + serverUrl: 'http://127.0.0.1:8200', sourceLinesErrorAppFrames: 5, sourceLinesErrorLibraryFrames: 5, sourceLinesSpanAppFrames: 0, @@ -541,8 +542,7 @@ class Config { const REDACT_FIELDS = { apiKey: true, secretToken: true, - serverUrl: true, - serverHost: true + serverUrl: true } const NICE_REGEXPS_FIELDS = { ignoreUrlRegExp: true, diff --git a/package-lock.json b/package-lock.json index 7f3ce03afb2..fe11a9ba999 100644 --- a/package-lock.json +++ b/package-lock.json @@ -17,7 +17,7 @@ "basic-auth": "^2.0.1", "cookie": "^0.5.0", "core-util-is": "^1.0.2", - "elastic-apm-http-client": "11.0.3", + "elastic-apm-http-client": "11.0.4", "end-of-stream": "^1.4.4", "error-callsites": "^2.0.4", "error-stack-parser": "^2.0.6", @@ -6155,9 +6155,9 @@ "dev": true }, "node_modules/elastic-apm-http-client": { - "version": "11.0.3", - "resolved": "https://registry.npmjs.org/elastic-apm-http-client/-/elastic-apm-http-client-11.0.3.tgz", - "integrity": "sha512-y+P9ByvfxjZbnLejgGaCAnwEe+FWMVshoMmjeLEEEVlQTLiFUHy7vhYyCQVqgbZzQ6zpaGPqPU2woKglKW4RHw==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/elastic-apm-http-client/-/elastic-apm-http-client-11.0.4.tgz", + "integrity": "sha512-449Qj/STi9hgnIk2KQ7719E7lpM3/i4Afs7NUhSOX8wV3sxn/+ItIHx9kKJthzhDDezxIfQcH83v83AF67GspQ==", "dependencies": { "agentkeepalive": "^4.2.1", "breadth-filter": "^2.0.0", @@ -20134,9 +20134,9 @@ "dev": true }, "elastic-apm-http-client": { - "version": "11.0.3", - "resolved": "https://registry.npmjs.org/elastic-apm-http-client/-/elastic-apm-http-client-11.0.3.tgz", - "integrity": "sha512-y+P9ByvfxjZbnLejgGaCAnwEe+FWMVshoMmjeLEEEVlQTLiFUHy7vhYyCQVqgbZzQ6zpaGPqPU2woKglKW4RHw==", + "version": "11.0.4", + "resolved": "https://registry.npmjs.org/elastic-apm-http-client/-/elastic-apm-http-client-11.0.4.tgz", + "integrity": "sha512-449Qj/STi9hgnIk2KQ7719E7lpM3/i4Afs7NUhSOX8wV3sxn/+ItIHx9kKJthzhDDezxIfQcH83v83AF67GspQ==", "requires": { "agentkeepalive": "^4.2.1", "breadth-filter": "^2.0.0", diff --git a/package.json b/package.json index 3d6701d6158..8425a15d891 100644 --- a/package.json +++ b/package.json @@ -93,7 +93,7 @@ "basic-auth": "^2.0.1", "cookie": "^0.5.0", "core-util-is": "^1.0.2", - "elastic-apm-http-client": "11.0.3", + "elastic-apm-http-client": "11.0.4", "end-of-stream": "^1.4.4", "error-callsites": "^2.0.4", "error-stack-parser": "^2.0.6", diff --git a/test/config.test.js b/test/config.test.js index f2c35489ea0..d66950babd5 100644 --- a/test/config.test.js +++ b/test/config.test.js @@ -148,7 +148,7 @@ var optionFixtures = [ ['secretToken', 'SECRET_TOKEN'], ['serverCaCertFile', 'SERVER_CA_CERT_FILE'], ['serverTimeout', 'SERVER_TIMEOUT', 30], - ['serverUrl', 'SERVER_URL'], + ['serverUrl', 'SERVER_URL', 'http://127.0.0.1:8200'], ['serviceName', 'SERVICE_NAME', apmName], ['serviceNodeName', 'SERVICE_NODE_NAME'], ['serviceVersion', 'SERVICE_VERSION', apmVersion],