Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Telemetry correlation headers are not included for all fetch requests #1240

Closed
MSNev opened this issue Apr 2, 2020 · 3 comments · Fixed by #1241
Closed

[BUG] Telemetry correlation headers are not included for all fetch requests #1240

MSNev opened this issue Apr 2, 2020 · 3 comments · Fixed by #1241
Assignees
Labels
Milestone

Comments

@MSNev
Copy link
Collaborator

MSNev commented Apr 2, 2020

I am experiencing the same as @tcihak-fqa, and I have a similar setup.

After upgrading @microsoft/applicationinsights-web to v2.5.3 (from v2.4.4), correlation headers are missing in all fetch requests.

I tested to enable the new W3C distributed tracing mode

{
    // ...
    distributedTracingMode: DistributedTracingModes.W3C
    // ...
}

...still no correlation headers of any sort.
No other distributedTracingMode options seem to work either.

This must be a bug, it worked before upgrading.

@MSNev :
I'm running an ASP.NET core app with kestrel on https://localhost:5001.

No fetch polyfill is used (polyfill for fetch is dynamically loaded only if the browser does not have it natively - with the browser I use for testing the native fetch API is supported).

I use JS modules (traspiled from TypeScript) and import @microsoft/applicationinsights-web - it is included in webpack bundling from node_modules.

The HTML/CSS/JS code is hosted in the same web application; on the same domain/port as the API I'm calling with fetch (where the correlation headers are missing). No CORS should be required.

FYI: It made no difference to add "localhost:5001" to correlationHeaderDomains,

I had a few more configuration settings than in my code below, but I have tested stripping the configuration down to a minimum as follows and I still have the problem:

import { ApplicationInsights, DistributedTracingModes } from "@microsoft/applicationinsights-web";

// ...
            const ai = new ApplicationInsights({
                config: {
                    //correlationHeaderDomains: ["localhost:5001"], // Made no difference
                    instrumentationKey: "the-instrumentation-key",
                    disableAjaxTracking: false,
                    disableCorrelationHeaders: false,
                    disableFetchTracking: false,
                    distributedTracingMode: DistributedTracingModes.AI, // .AI_AND_W3C or .W3C also does not add any correlation headers
                }
            });

            ai.loadAppInsights();

@josundt I think I found the root cause for your issue, basically the code is adding the headers to the intercepted fetch request however if you don't pass the optional 2nd parameter (init), it creates one internally and populated the headers on this object... BUT, it doesn't pass this onto the real fetch!!!

As a workaround, if you pass a value as part of this 2nd parameter the headers should be sent correctly.

@MSNev
Copy link
Collaborator Author

MSNev commented Apr 8, 2020

Fixed deployed as NPM and next CDN channels

@MSNev MSNev removed the fixed - waiting release PR Committed and waiting deployment label Apr 8, 2020
@MSNev
Copy link
Collaborator Author

MSNev commented Apr 8, 2020

Now also fully deployed to primary CDN

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 15, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
1 participant