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

**URL:** <https://discuss.elastic.co/t/use-startspan-set-mariadb-but-haven-t-seen-it-on-destination-and-service-map/335767>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [June 12, 2023, 12:00pm UTC](https://discuss.elastic.co/t/use-startspan-set-mariadb-but-haven-t-seen-it-on-destination-and-service-map/335767 "2023-06-12T12:00:20Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KURT07](https://avatars.discourse-cdn.com/v4/letter/k/e9a140/32.png) [@KURT07](https://discuss.elastic.co/u/KURT07)\
**Post date:** [June 12, 2023, 12:00pm UTC](https://discuss.elastic.co/t/use-startspan-set-mariadb-but-haven-t-seen-it-on-destination-and-service-map/335767/1 "2023-06-12T12:00:20Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![trentm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/trentm/32/77647_2.png) [@trentm](https://discuss.elastic.co/u/trentm)\
**Post date:** [June 12, 2023, 10:10pm UTC](https://discuss.elastic.co/t/use-startspan-set-mariadb-but-haven-t-seen-it-on-destination-and-service-map/335767/2 "2023-06-12T22:10:05Z")

</div>

Hi @KURT07. Thanks for the question.

Try this:

```js
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:

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

```

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

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 10, 2023, 10:10pm UTC](https://discuss.elastic.co/t/use-startspan-set-mariadb-but-haven-t-seen-it-on-destination-and-service-map/335767/3 "2023-07-10T22:10:55Z")

</div>

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