3

I have a azure app based on azure functions. Lets say it consists of two apps named A and B, and that A and B have the following functions:

A:

  • func_A_1
  • func_A_2

B:

  • func_B_1
  • func_B_2
  • func_B_3

App A and B are connected by a HTTP post from func_A_2 that triggers func_B_1. All the other functions are connected (1 -> 2 for A and 1 -> 2 -> 3 for B) with service bus queues. The whole app is written in Java.

At the moment we get a trace in application insights that looks like this

func_A_1 -> func_A_2 -> HTTP POST -> func_B_1 -> func_B_2 -> func_B_3

and the request id table looks like this (simplified)

Function Operation Id Id Parent Id
func_A_1 AAA 1 AAA
func_A_2 AAA 2 1
HTTP POST AAA 3 2
func_B_1 AAA 4 3
func_B_2 AAA 5 4
func_B_3 AAA 6 5

And all calls under the same operation id. Which is perfect. But this only works when we are running our applications on windows instances. For other reasons we had to change to Linux instances. From the documentation it seems like HTTP requests for Java instances on Linux is not automatically tracked, which means we get two separate traces under two different operation id's like this:

func_A_1 -> func_A_2

func_B_1 -> func_B_2 -> func_B_3

and the request id table looks like this (simplified)

Function Operation Id Id Parent Id
func_A_1 AAA 1 AAA
func_A_2 AAA 2 1
func_B_1 BBB 3 BBB
func_B_2 BBB 4 3
func_B_3 BBB 5 4

As a solution my idea is to make a custom telemetry to handle the missing HTTP POST trace.

From the ExecutionContext i can use getTraceContext().getTraceparent() to get both the Id and operation Id in func_A_2 as it has the form: 00-AAA-2-00. My idea is to send this information along in the HTTP header of the post. Then in the beginning of func_B_1 I will create a custom telemetry called HTTP POST with (parentId = 2, operationId = AAA, id = 3), I guess this will make it appear beneath func_A_2 in the application insight trace. However, I would like to still use azures automatic tracing for the (func_B_1 -> func_B_2 -> func_B_3) chain. Which means I somehow have to change the ExecutionContext parentId and operationId of func_B_1 to 3 and AAA (and azure will hopefully carry the new operation Id through the chain for me, and create new id's for function 1 to 3). But I can't find any ways to achieving this. I tried using:

RequestTelemetryContext context = new RequestTelemetryContext()
context.getHttpRequestTelemetry().getContext().getOperation().setId("AAA")
context.getHttpRequestTelemetry().getContext().getOperation().setParentId("2")
ThreadContext.setRequestTelemetryContext(context)

However, this does not seem to change the actual Id's in Azure application insights of the automatic generated telemetry. Maybe my approach is just not possible. But any help that can get me to a solution is appreciated.

  • 1
    Can you please paste an example of operation ids, ids and parent ids? There is W3C standard and old Application Insights-specific standard. This will help to see whether one of the parties works only with one of these standards. – ZakiMa Sep 19 '21 at 06:36
  • I've come a bit further. Adding traceparent from w3c standard to the http header connects them. This makes it possible to solve my issue I think. However, this also revealed the real issue for me. In Java windows instances request and depency telemetry was collected by application insights and everything worked. But on Linux instances no depency telemetry is collected only requests. I think I can code all the dependency telemetry by hand, but ultimately there must be a way to get linux to collect depency telemetry as well, which is the correct solution – Anders Nørløv Berthelsen Sep 19 '21 at 09:49
  • By the way here are the ID examples: Operation id: d3aab68866ff1f4ebfc93667dc1e25d1 Id: 38741f40705cd646 Pearent id: eb0be82cd4f4ef9c – Anders Nørløv Berthelsen Sep 19 '21 at 09:52
  • 1
    Doing some further research I think I found that HTTP dependencies on Linux is not autogenerated as it is on windows. So using the w3c standard traceparent actually fixes my problem. – Anders Nørløv Berthelsen Sep 20 '21 at 15:04

0 Answers0