grafana / faro-web-sdk

The Grafana Faro Web SDK, part of the Grafana Faro project, is a highly configurable web SDK for real user monitoring (RUM) that instruments browser frontend applications to capture observability signals. Frontend telemetry can then be correlated with backend and infrastructure data for full-stack observability.
https://grafana.com/oss/faro/
Apache License 2.0
739 stars 64 forks source link

TracingInstrumentation for micro frontends #568

Open pietrarenner opened 5 months ago

pietrarenner commented 5 months ago

Hi!

I have a micro frontend application that I have been monitoring using Faro. I have initialized one Faro instance per micro frontend and set the isolate variable to true in all of them, except for the one that has my global scope. I have also initialized the TracingInstrumentation in all of them. The problem is that traces that come from different micro frontends are considered to come from the same mfe, at least that is what is show to me in Grafana Cloud. For example, I have an mfe called A that sends a request to http://localhost:8000/ and a micro frontend called B that sends a request to http://localhost:8000/b. A never sends a request to http://localhost:8000/b, but, when the request is sent to that url, what appears in Grafana Cloud is as if the request had been sent by A.

Is there a way for me to solve this? I am not quite sure what I have done wrong.

codecapitano commented 5 months ago

Hi @pietrarenner I don't have a quick fix yet but I think I know what we need to change in the web-tracing package to better support microfrontends.

pietrarenner commented 5 months ago

Thank you for the response, @codecapitano! I will be waiting for those changes!

codecapitano commented 5 months ago

Hi @pietrarenner I fear that the solution is not that straight forward.

The thing is that we can only register one WebTracerProvider in the browsing context. So even if you have multiple Faro instances they will all use the same WebTracerProvider.

Though it's possible to get multiple independent Tracers in otel. But the auto instrumentations we use under the hood always use the same tracer and do not allow to inject other tracers.

See: opentelemetry-instrumentation

So I think if you really need a tracer per micro frontend for now the only possibility is to instrument manually for example as explained in the faro docs or configure only a single tracers.

But I'll investigate further.

Cheers, Marco

ValeraKorovelkov commented 3 weeks ago

Hi @pietrarenner. Did manual instrumentation for each MFE resolve your issue?

ValeraKorovelkov commented 3 weeks ago

@codecapitano Hey! I have the same issue and tried to instrument my MFEs manually using the guide you provided, but I'm encountering a few errors. Could you pls help?

@opentelemetry/api: Attempted duplicate registration of API: trace
@opentelemetry/api: Attempted duplicate registration of API: context
@opentelemetry/api: Attempted duplicate registration of API: propagation

Sorry, I missed the part about having only one Provider in your last comment. I will try registering multiple Tracers instead. However, will they appear as separate applications in Grafana Cloud, as requested in the original topic?