# Service Map not linking services

**URL:** <https://discuss.elastic.co/t/service-map-not-linking-services/262096>\
**Category:** APM\
**Tags:** dotnet\
**Created:** [January 25, 2021, 11:44am UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096 "2021-01-25T11:44:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![jhai](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@jhai](https://discuss.elastic.co/u/jhai)\
**Post date:** [January 25, 2021, 11:44am UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096/1 "2021-01-25T11:44:48Z")

</div>

**Kibana version** : 7.9

**Elasticsearch version** : 7.9

**APM Server version** : 7.10

**APM Agent language and version** : Elastic.Apm.AspNetCore 1.7.1

**Browser version** : Chrome 87

**Original install method (e.g. download page, yum, deb, from source, etc.) and version**: Download Page / Nuget

**Fresh install or upgraded from other version?** Fresh

**Is there anything special in your setup?** No

**Description of the problem including expected versus actual behavior. Please include screenshots (if relevant)**:  
I have a number of Mock services calling REST APIs. A transaction is accurately recorded with each service involved shown in the trace. The documents in the apm\* indexes look correct with the required association (traceid, parentid, etc) all looking correct. However, the Service Maps Tab shows 4 unlinked services. I would have expected that a call from one service to another would show as a line with some metrics associated.

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

![image](https://us1.discourse-cdn.com/elastic/original/3X/5/3/53650861ead0126e3c4158acc460685102bcba8b.png)

**Steps to reproduce** :

1. Setup Dotnet Core programs/services with APM Agents
2. Capture APM metrics for programs/services with trace id lineage through all
3. Open Service Maps tab and see that services are not linked

**Errors in browser console (if relevant)**: No errors

**Provide logs and/or server output (if relevant)**:

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/e/c/ec173d1882ca56e1c62fe683b7a2ccac6cd911f8.png)

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [January 26, 2021, 6:33pm UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096/2 "2021-01-26T18:33:02Z")

</div>

Hi @jhai,

Are these services calling each other with `HttpClient`? The transaction flow looks a bit strange to me. For example I see the "Event Start" transaction, but then there seems to be no span, below that we immediately see the "HTTP 2xx GET PutData/Create" transaction. There should be an outgoing HTTP request between those. What I wanna get with this is that this may not be related directly to the server map - to me it looks there is another problem here with missing spans.

So if you could give me more info about that app (how do the services call each other? Thing like that), that'd help.

Other thing that could help is logs from these apps on `Trace` level - would it be possible for you to upload those here?

Greg

---

<div class="post-metadata">

**Author:** ![jhai](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@jhai](https://discuss.elastic.co/u/jhai)\
**Post date:** [January 29, 2021, 2:36pm UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096/3 "2021-01-29T14:36:08Z")

</div>

Hi @GregKalapos,

Thanks for looking into this. Yes, I am using HttpClient calls to web apis.  
I started with minimum explicit instrumentation, which is why there is an absence of spans above.

Its not very clear from the documentation what makes Service Maps work, whether the flow is determined from Services/Transactions/Spans.

Is it correct that I need to manually include Traceparent in the header of the request or should this be added automatically?

 ![image](https://us1.discourse-cdn.com/elastic/original/3X/a/1/a1035cfd21f57f5cd98a62eb46b877633c5b5985.png)

Here is HttpClient request from Ws to Ws2:

```auto
        var t = Agent.Tracer.CurrentTransaction;
        var s = t.StartSpan("Api1 Span1", "Api Call");
        Uri uri = new Uri("http://localhost:44391/api/HandleData?text=" + text);
        var a = Agent.Tracer.CurrentTransaction?.OutgoingDistributedTracingData.SerializeToString();
        client.DefaultRequestHeaders.Add("traceparent", a);

        HttpResponseMessage webResponse = await client.GetAsync(uri);
        s.End();

```

I also not that the Time Spent by Span chart is also blank, not sure if this is related.

Thanks

---

<div class="post-metadata">

**Author:** ![GregKalapos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gregkalapos/32/37205_2.png) [@GregKalapos](https://discuss.elastic.co/u/GregKalapos)\
**Post date:** [February 2, 2021, 4:36pm UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096/4 "2021-02-02T16:36:20Z")

</div>

Hi @jhai,

Below I answer your questions, but before I do so: You can do manual instrumentation for most part and still enable auto instrumentation for outgoing HTTP.

For that, you can simply do this:

```auto
Elastic.Apm.Agent.Subscribe(new HttpDiagnosticsSubscriber());

```

The `HttpDiagnosticsSubscriber` will turn on auto instrumentation for outgoing HTTP calls. This means each time an outgoing HTTP call happens, the agent will capture it as a span IF there is an active transaction. This means you’ll still need to start your transactions manually (with `Tracer.StartTransaction` or `Tracer.CaptureTransaction`), but within a transaction HTTP calls will be automatically captured – so you don’t need any of the span related code (no ` t.StartSpan`, etc.)

The good part about this is that you don’t need to take care of the traceparent header and the whole service map thing will also work – the agent will take care of it automatically.

If you still want to do this manually, you need to do more work. Let me answer your questions, with that it will be hopefully clear what you need to do. But again, I’d rather suggest using `HttpDiagnosticsSubscriber` and let the agent take care of this.

> Its not very clear from the documentation what makes Service Maps work, whether the flow is determined from Services/Transactions/Spans.

Yeah, I agree, we don’t really document this. Service map uses the [`destination`](https://github.com/elastic/apm-server/blob/master/docs/spec/v2/span.json#L84) field on spans. These fields are reflected on the public API in C# like this:

```auto
transaction.CaptureSpan("foo", "bar", span =>
{
	span.Context.Destination = ...
});

```

But you don’t really need it – the agent deduces it from other fields. Specifically for HTTP calls it uses the `span.Context.Http` field to fill the `destination` field, so `span.Context.Http` must be set and the agent will do its job to fill necessary fields for the service map.

> Is it correct that I need to manually include Traceparent in the header of the request or should this be added automatically?

For the service map you don’t really need that, it only uses the fields I mentioned above. But you’ll still need to manually include the traceparent header in order to make sure the whole thing ends up in a single trace.

But `Elastic.Apm.Agent.Subscribe(new HttpDiagnosticsSubscriber());` takes care of both of these things (the destination field and the traceparent header).

I hope this helps.  
Greg

---

<div class="post-metadata">

**Author:** ![jhai](https://avatars.discourse-cdn.com/v4/letter/j/b77776/32.png) [@jhai](https://discuss.elastic.co/u/jhai)\
**Post date:** [February 6, 2021, 7:31pm UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096/5 "2021-02-06T19:31:39Z")

</div>

Thanks Greg. This is clear to me now and I am able to see the service maps.

---

<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:** [February 27, 2021, 3:32pm UTC](https://discuss.elastic.co/t/service-map-not-linking-services/262096/6 "2021-02-27T15:32:25Z")

</div>

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