faro-web-sdk icon indicating copy to clipboard operation
faro-web-sdk copied to clipboard

TracingInstrumentation for micro frontends

Open pietrarenner opened this issue 1 year ago • 5 comments

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.

pietrarenner avatar Apr 25 '24 18:04 pietrarenner

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.

codecapitano avatar Apr 29 '24 10:04 codecapitano

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

pietrarenner avatar Apr 29 '24 18:04 pietrarenner

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

codecapitano avatar Apr 30 '24 15:04 codecapitano

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

ValeraKorovelkov avatar Sep 06 '24 14:09 ValeraKorovelkov

~~@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?

ValeraKorovelkov avatar Sep 09 '24 12:09 ValeraKorovelkov