Use startSpan Set Mariadb But Haven’t Seen It On Destination And Service Map

Use startSpan set Mariadb
i’ve Seen Type Mariadb On Timeline
But Haven’t Seen It On Destination And Service Map

APM Server version:
8.5.3

APM Agent language and version:
elastic-apm-node : 3.41.1

// My code
const transaction = Agent.currentTransaction;
const dbSpan = transaction.startSpan();
dbSpan.type = "db";
dbSpan.subtype = "mariadb";
dbSpan.action = "query";
dbSpan.name = "SELECT 1";
dbSpan.end();

Any idea what Im doing wrong?
Please Help
Many Thanks.

Hi @KURT07. Thanks for the question.

Try this:

var apm = require('./').start({
    serviceName: 'mariadb-example',
    metricsInterval: '0s'
})

function main() {
    const transaction = apm.startTransaction('manual')
    const dbSpan = transaction.startSpan('SELECT 1', 'db', 'mariadb', 'query', { exitSpan: true })
    // ...
    dbSpan.end()
    transaction.end()
}

main()

The important difference here is the exitSpan: true option when creating the span. The APM agent only normally includes so-called "exit" spans -- spans that represent a call to an external service -- for Service Maps and Dependencies.

When a span is marked as an exit span, then it will set a reasonable value for service target fields used for the Service Map node. By default it uses the span.subtype -- in this case "mariadb".

If you want to further customize that, for example, to distinguish mutliple MariaDB endpoints or databases, then you could use:

dbSpan.setServiceTarget('mariadb', 'mydb')

which should result in a "mariadb/mydb" node in the ServiceMap.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.