---
title: "Measuring a hybrid request chain with Application Insights - Twyzer"
description: "How we used a custom traceparent header and one KQL query in Application Insights to split a slow hybrid Azure request into per-hop timings across each layer."
url: "https://twyzer.nl/blogs/measuring-a-hybrid-request-chain-with-application-insights/"
language: "nl-NL"
---

# Measuring a hybrid request chain with Application Insights

Technologie24 november 2026

![Portret van Wout den Buurman, Engineer bij Twyzer](https://twyzer.nl/media/uploads/2026/07/1Y1A6141-e1786612469988.jpg?width=200 "Wout den Buurman")

Geschreven door

Wout den Buurman - Engineer

For one of our customers, we are moving a Java integration layer to Azure as-is: the code should migrate without changes, only the platform changes. The database remains on-premises. That combination turns out to be an interesting place to measure, because the proof of concept must answer a simple question: does this perform well enough in Azure?

![Twee collega's kijken samen naar een monitor in het kantoor](https://twyzer.nl/media/uploads/2026/07/1Y1A6512.jpg?width=1200 "Samen naar het scherm kijken")

![](https://twyzer.nl/static/gradient.jpg)

## **Situation**

The chain has a few components. Requests come in through API Management and hit a business services API, which calls a separate data services API, which talks to the Oracle database that is still on-premises. Both Java apps run on Tomcat on Azure App Service. For caching, the business services use a Redis cache, which is also on-premises.

The important consequence of leaving the database and the cache on-premises: every call to either of them that used to go over the switch next to the server now goes over ExpressRoute. Sub-millisecond on a local network becomes roughly 20 to 30 milliseconds.

We built a small C# app that sends requests, handles the API Management subscription key and the Entra token, calls each endpoint both cold (hitting the database) and warm (served from Redis), and writes the results to CSV. This made it easy to load test the APIs, and it gave us exactly what we needed: a wall-clock number per call. Some calls took minutes, which we needed to dig into.

## **The problem with one number**

“This call takes several minutes” is not a finding. It is a question: what exactly happens during those minutes?

The time could be hiding in a few places: processing inside the services, the HTTP hop to the data services, the database calls to on-premises, or Redis. Each of those points in a different direction, from code changes and App Service Plan sizing to network problems or database queries. During a load test, though, we had no simple way to measure those parts separately.

## **Correlating our own measurements with Azure’s**

We did not have to change the Java apps to get that split. Both already ran with the Application Insights Java agent, which attaches itself to the JVM and records incoming requests, outgoing HTTP calls, JDBC calls and Redis operations. Everything is written to two tables: requests and dependencies. Every item carries an operation\_Id that is the same for all spans belonging to one transaction.

What was missing was a way to tie that back to our own measurements. The Java agent uses W3C Trace Context for correlation by default. If no traceparent header comes in, the agent generates a trace id itself and propagates it downstream. So the chain is already stitched together, but Azure picks the id, and there is no way to tell which of a thousand traces belongs to the specific run that was slow.

Sending the header ourselves fixes that, because then we choose the id before the call goes out. A traceparent header has the format **00-<32 hex trace id>-<16 hex parent id>-01**. The trace id part becomes the operation\_Id on every span in Azure, and we write it to the CSV next to our own timing. The 01 at the end marks the trace as sampled, which matters more than it looks (see below). Because requests pass through API Management first, it is also worth checking that the Application Insights diagnostics in API Management use W3C as the correlation protocol.

## **Splitting a request into hops**

With correlation working, the breakdown comes out of one query. Every span can be assigned to a hop based on which table it came from, which app logged it, and its dependency type:

Kopieer

```
let bs = "app-business-services-api";let ds = "app-data-services-api";union requests, dependencies| where timestamp > ago(1h)| extend hop = case(    itemType == "request" and cloud_RoleName == bs, "BS_total",    itemType == "dependency" and cloud_RoleName == bs and type =~ "redis", "BS_Redis",    itemType == "dependency" and cloud_RoleName == bs, "BS_to_DS",    itemType == "request" and cloud_RoleName == ds, "DS_total",    itemType == "dependency" and cloud_RoleName == ds and type =~ "redis", "DS_Redis",    itemType == "dependency" and cloud_RoleName == ds, "DS_Oracle",    "other")| summarize hop_ms = sum(duration) by operation_Id, hop| summarize    BS_total = coalesce(sumif(hop_ms, hop == "BS_total"), 0.0),    BS_Redis = coalesce(sumif(hop_ms, hop == "BS_Redis"), 0.0),    BS_to_DS = coalesce(sumif(hop_ms, hop == "BS_to_DS"), 0.0),    DS_total = coalesce(sumif(hop_ms, hop == "DS_total"), 0.0),    DS_Redis = coalesce(sumif(hop_ms, hop == "DS_Redis"), 0.0),    DS_Oracle = coalesce(sumif(hop_ms, hop == "DS_Oracle"), 0.0)    by operation_Id| extend    BS_processing = max_of(BS_total - BS_to_DS - BS_Redis, 0.0),    Network_BS_DS = max_of(BS_to_DS - DS_total, 0.0),    DS_processing = max_of(DS_total - DS_Oracle - DS_Redis, 0.0)The last three lines are where it gets interesting. The network between two App Services is not instrumented, so it has no span of its own. But you can still work it out. The business services know how long their call to the data services took, and the data services know how long they spent handling that call. The difference between the two is the time spent on the network and in the App Service front ends.
```

The same subtraction gives you each app’s own processing time: its total duration minus everything it handed off to Redis, the database or the other app.

Grouping on the request name as well gives the same breakdown per endpoint. And because our own measurements record which trace ids belonged to a cold or a warm run, we could split on that too. The result is a table that shows, for each endpoint, how many milliseconds went to each app, to the network between them, to the database and to Redis.

Two limitations are worth knowing. The buckets are broader than their names: **BS\_to\_DS** contains every non-Redis dependency of the business services, so a token call would end up there too, and the same goes for **DS\_Oracle**. If your apps call more than that, filter on target or name. And the query adds up durations, so if an app runs dependencies in parallel, the sum is larger than the time that actually passed, and its processing time comes out too low.

## **Making sure every span arrives**

The subtraction only works if every span of a transaction actually arrives in Application Insights. If one is missing, coalesce turns it into 0 ms and max\_of hides the negative result. The table still looks clean, but it points at the wrong layer. If the data services request span is dropped, for example, the entire call to the data services is counted as network time.

During a load test, the most likely cause is sampling. Since version 3.4.0, the Java agent defaults to rate-limited sampling of roughly five requests per second, which a load test passes easily. For the measurements, we set sampling to 100% on both App Services and turned it back down afterwards. You can do this with the app setting **APPLICATIONINSIGHTS\_SAMPLING\_PERCENTAGE=100** or with **“sampling”: { “percentage”: 100 }** in applicationinsights.json. Also send **01** as the trace flag, and keep in mind that ingestion sampling and a daily cap on the Application Insights resource can drop data as well.

It is also worth checking the result: every trace id you sent should come back with both a **BS\_total** and a **DS\_total**. Transactions with missing hops are better left out than counted as zero.

## **What the breakdown made visible**

The value of the split is that it points at one layer instead of four. Warm reads from the cache spent their time where you would expect. One cache rebuild, however, made more than 21,000 individual database calls in a single request, at about 22 ms each. That adds up to roughly 460 seconds, close to eight minutes, and more than 75% of the request’s duration.

None of those calls were slow; ExpressRoute performed well. There were just too many of them. On-premises, at sub-millisecond latency, the same 21,000 calls add up to well under half a minute, so this had never been an issue.

## **Conclusion**

The measurement setup is the part we would reuse. It comes down to three things: a client that injects a traceparent and records the trace id next to its own timings, an agent that was already logging everything (with sampling at 100% during the test), and a query that buckets spans into hops and subtracts to get the hops that have no span of their own.
