# Figure out how to link services using manual instrumentation

**URL:** <https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027>\
**Category:** APM\
**Tags:** nodejs\
**Created:** [September 1, 2021, 11:07am UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027 "2021-09-01T11:07:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jagraj02](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jagraj02/32/94011_2.png) [@Jagraj02](https://discuss.elastic.co/u/Jagraj02)\
**Post date:** [September 1, 2021, 11:07am UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027/1 "2021-09-01T11:07:48Z")

</div>

I have three sample services that I am trying to instrument. Service 1 is linked to Service 2 via rest while Service 2 acts a producer for service 3 (uses AWS SQS). Service 3 is a consumer from SQS.

I have 2 different scenarios which I am trying to understand here.

**Here is the code for service 2.**

```auto
@Get('/sendMessage')
  async sendMessage(@Headers() requestHeaders: any) {
    const activeSpanContext = trace.getSpanContext(context.active());
    return await this.appService.InsertMessage(activeSpanContext);
  }

```

**Scenario 1 :**

**Code for service 3 :**

```auto
const recievedMessages = await appService.recieveMessage();
    let activeSpan = trace.getSpan(context.active());
    if (recievedMessages) {
      for (let message of recievedMessages) {
        let contextWeGot = JSON.parse(message['Body'])['ctx'];
        const newCTX = trace.setSpanContext(context.active(), contextWeGot);
        track.startActiveSpan('HTTP GET', {}, newCTX, async (span) => {
          console.log(`Processing Message : ${message['Body']}`);
          span.end();
        });
      }

```

**Service Map :**

 ![MicrosoftTeams-image](https://us1.discourse-cdn.com/elastic/original/3X/f/f/ff417659099e54899135cd0f73f89a7bbb8403c7.png)

**Scenario 2:**

**Code for service 3:**

```auto
const recievedMessages = await appService.recieveMessage();
    let activeSpan = trace.getSpan(context.active());
    if (recievedMessages) {
      for (let message of recievedMessages) {
        let contextWeGot = JSON.parse(message['Body'])['ctx'];
 
        const newCTX = trace.setSpanContext(context.active(), contextWeGot);
 
        // trace.setSpanContext(newCTX, Outerspan);
        track.startActiveSpan('HTTP GET', {}, newCTX, async (span) => {
          console.log(`Processing Message : ${message['Body']}`);
          axios
            .get('https://google.com', {
              headers: {
                ctx: JSON.stringify(trace.getSpanContext(context.active())),
              },
             })
             .then((response) => {
              return response.data;
            });
          span.end();
        });
      }

```

**Service Map:**

 ![MicrosoftTeams-image (1)](https://us1.discourse-cdn.com/elastic/original/3X/3/0/30717960fe9c84ea339c9f16b055256f559359d3.png)

**Question:** When I am using just my custom span in service 3, in the service map it shows as a disconnected service, but when I include an axios call (auto-instrumented) in my custom span in service 3, service 3 is then shown as a connected service.

---

<div class="post-metadata">

**Author:** ![cyrilleleclerc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyrilleleclerc/32/60493_2.png) [@cyrilleleclerc](https://discuss.elastic.co/u/cyrilleleclerc)\
**Post date:** [September 1, 2021, 2:21pm UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027/2 "2021-09-01T14:21:47Z")

</div>

Thanks Jagraj, for the record, this is a case using OpenTelemetry that was initially posted on OpenTelemetry JS repo's [Services not linking in Elastic APM service Map · Discussion #2445 · open-telemetry/opentelemetry-js · GitHub](https://github.com/open-telemetry/opentelemetry-js/discussions/2445)

---

<div class="post-metadata">

**Author:** ![Jagraj02](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jagraj02/32/94011_2.png) [@Jagraj02](https://discuss.elastic.co/u/Jagraj02)\
**Post date:** [September 1, 2021, 4:22pm UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027/3 "2021-09-01T16:22:23Z")

</div>

Seems like span attributes played a major role for a span to show up on the map.

```auto
'messaging.system': 'AmazonSQS',
'messaging.destination_kind': 'queue',
'messaging.destination': 'our_destination_3',
'messaging.operation': 'process',

```

Can you also shed some more light here..?

---

<div class="post-metadata">

**Author:** ![cyrilleleclerc](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cyrilleleclerc/32/60493_2.png) [@cyrilleleclerc](https://discuss.elastic.co/u/cyrilleleclerc)\
**Post date:** [September 1, 2021, 7:52pm UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027/4 "2021-09-01T19:52:04Z")

</div>

Can you please confirm you use Elastic v7.14 (APM Server, Elasticsearch, and Kibana)?  
We have added support for visualization of OpenTelemetry messaging in the Service Map in v7.14 with [[OpenTelemetry] Map OpenTelemetry `messaging.*` semantic conventions to Elastic Common Schema · Issue #5094 · elastic/apm-server · GitHub](https://github.com/elastic/apm-server/issues/5094)

Please verify the spanKind of the producer, it must be SpanKind Producer (see [translate otel messaging.\* to ecs by stuartnelson3 · Pull Request #5334 · elastic/apm-server · GitHub](https://github.com/elastic/apm-server/pull/5334/files#diff-8e54cca46d89cab842501bd75b6c71b1276ee39356093a4a0fcb9d121cdc8f23R668))

On the consumer, please set the SpanKind accordingly to Consumer (see [translate otel messaging.\* to ecs by stuartnelson3 · Pull Request #5334 · elastic/apm-server · GitHub](https://github.com/elastic/apm-server/pull/5334/files#diff-02c6ec658949ac9342275dab8172631374412b8037a4d57d321f227e0c3a8c2cR525) )

Please also fill `net.peer.ip`

---

<div class="post-metadata">

**Author:** ![Jagraj02](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jagraj02/32/94011_2.png) [@Jagraj02](https://discuss.elastic.co/u/Jagraj02)\
**Post date:** [September 2, 2021, 2:34pm UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027/5 "2021-09-02T14:34:30Z")

</div>

@cyrilleleclerc thanks a lot. It worked like a charm.

---

<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:** [September 23, 2021, 10:35am UTC](https://discuss.elastic.co/t/figure-out-how-to-link-services-using-manual-instrumentation/283027/6 "2021-09-23T10:35:28Z")

</div>

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