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

🐛 API calls are not logged with withFetch() API in newer versions of Angular #2911

Closed
gokberknur opened this issue Aug 1, 2024 · 5 comments
Labels
bug Something isn't working

Comments

@gokberknur
Copy link

gokberknur commented Aug 1, 2024

if you configure an angular app with new "withFetch()" flag.

https://angular.dev/api/common/http/withFetch

api calls are not logged in datadogRUM.

we updated our application to angular v18 and started to use withFetch() flag in Angular's httpClient. We noticed that our API calls are not being logged anymore in datadog RUM.

To reproduce this issue you can try this sample-repo with fetch flag and without it in Angular HttpClient, then check the logs from RUM panel.
https://github.com/gokberknur/datadogRumNg18/blob/main/main.ts

@gokberknur gokberknur added the bug Something isn't working label Aug 1, 2024
@N-Boutaib
Copy link
Contributor

N-Boutaib commented Aug 5, 2024

Hello @gokberknur,

Thanks for reaching out. Indeed, in the example you provided, when forcing Angular to use fetch by default instead of XHR, the SDK does not capture resources sent. In fact, this is happening because Angular doen't use window.fetch directly, but instead uses a patched version kept somewhere else.

To solve this issue we suggest to either:

  • Load and initialise the SDK using CDN synchronously before Angular.
  • Initialise the SDK before calling bootstrapApplication method. To be able to use the SDK in other components, you can simply injects in them. Following is a simple example:
// main.ts
import { datadogRum } from '@datadog/browser-rum';
datadogRum.init({
  applicationId: 'xxx',
  clientToken: 'xxx',
  service: 'xxx',
  env: 'dev',
  trackViewsManually: true,
});

// App logic

// Make datadogRum injectable and accessible in other components
platformBrowserDynamic([{ provide: DD_RUM, useValue: datadogRum }])
  .bootstrapModule(AppModule)
  .catch((err) => console.error(err));

@gokberknur
Copy link
Author

Thank you for your reply.

I think datadog rum is already initialized synchronously in our application, and it still doesn't work. However, we are not in favor in this solution anyway, considering size of the datadog-rum package is already big. Currently we removed the "WithFetch()" flag and using XHR.

I hope datadog will support this in the near future.

@BenoitZugmeyer
Copy link
Member

I hope datadog will support this in the near future.

This is not something we can fix without a change in Angular. I submited an issue to see if they would be willing to support this use case.

@gokberknur
Copy link
Author

Thank you so much for your investigation! @BenoitZugmeyer

@gokberknur
Copy link
Author

It looks angular team released v18.2.3 that fixing this issue. I tried locally and i see API request now.

https://github.com/angular/angular/releases/tag/18.2.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants