Skip to content

Error when elasticsearch config hosts property is an array #1762

@brad-gardner

Description

@brad-gardner

Describe the bug

When you have an elasticsearch config similar to this:

 elasticsearch: {
        host: [
            {
                host: process.env.ELASTIC_HOST,
                auth: process.env.ELASTIC_AUTHENTICATION,
                protocol: process.env.ELASTIC_PROTOCOL,
                port: process.env.ELASTIC_PORT
            }
        ],
        log: 'error',
        requestTimeout: 60000
    }

The updated APM code crashes because it's not anticipating the array for the host property.

Issue was introduced in this commit: aa8eb56#diff-daccb535f6ab4446fed3816cc2a6dc92

Specifically this bit of code in the elasticsearch module:

// get the remote host information from elasticsearch Transport options
const transportConfig = this._config
let host, port
if (typeof transportConfig === 'object' && transportConfig.host) {
    [host, port] = transportConfig.host.split(':')
}
span.setDestinationContext(getDBDestination(span, host, port))

The host.split is where the error occurs: "TypeError: transportConfig.host.split is not a function or its return value is not iterable"

To Reproduce

Steps to reproduce the behavior:

  1. Use an array to specify one or more hosts for the elasticsearch client
  2. Use the latest release of the apm client.

Expected behavior

APM should be able to handle host specified as an array.

Environment (please complete the following information)

  • OS: OSX and Ubuntu, should apply to any
  • Node.js version: testing on 12, should be an issue for all
  • APM Server version: latest in elastic cloud
  • Agent version: 3.6.1

How are you starting the agent? (please tick one of the boxes)

  • [ X] Calling agent.start() directly (e.g. require('elastic-apm-node').start(...))
  • Requiring elastic-apm-node/start from within the source code
  • Starting node with -r elastic-apm-node/start

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-nodejsMake available for APM Agents project planning.bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions