Cannot override x-forwarded-to on API Management

Dimitry Nechaev 20 Reputation points
2025-08-11T07:32:28.4133333+00:00

I would like to use APIM to proxy App Insights endpoint for a website front - end (javascript)

Reasons:

  • Any ad blocker will block app insights entirely.
  • Don't want to expose telemetry key.

Problem 1 - cannot collect client IP address. This is important for a public e-commerce website with lots of synthetic traffic.

Problem 2 - Following Microsoft documentation does not work.

I need a very simple thing - overwrite x-forwarded-for with client's IP address. That's all.

Here is my attempt:

    <inbound>
        <find-and-replace from="MYINSTRUMENTATIONKEY" to="123-456-678-fffff-ddsdfgsfdd" />
        <set-header name="X-Forwarded-For" exists-action="override">
            <value>@(context.Request.IpAddress)</value>
        </set-header>
        <set-header name="X-Forwarded-For-Test" exists-action="override">
            <value>@(context.Request.IpAddress)</value>
        </set-header>
        <set-backend-service base-url="https://testmock.free.beeceptor.com" />
    </inbound>

Outcome:

  • "x-forwarded-for-test" shows my ip.
  • "x-forwarded-for" nailed to APIM ip. No Matter What.

What's wrong?

My APIM is Basic v2

Azure API Management
Azure API Management
An Azure service that provides a hybrid, multi-cloud management platform for APIs.
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.