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.