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

Allow additional TracingInstrumentations without re-implementing getIgnoreUrls() or faro.initialize() #711

Open
pshahid opened this issue Oct 23, 2024 · 0 comments

Comments

@pshahid
Copy link

pshahid commented Oct 23, 2024

Description

When attempting to insert additional TracingInstrumentations other than the default OTEL tracing instrumentations, Faro web-tracing currently requires that we call getDefaultOtelInstrumentations() with the same arguments as https://github.com/grafana/faro-web-sdk/blob/main/packages/web-tracing/src/instrumentation.ts#L102. However, this is not possible as getIgnoreUrls() is a private function, so calling faro.getIgnoreUrls() is not possible from outside of the class.

As an example, today I was trying to add a couple of opentelemetry/instrumentation into our app (which does not already use opentelemetry on the frontend). To do this I expected I could just add them to the instrumentation list, like this:

initializeFaro({
  instrumentations: [
    ...getWebInstrumentations(),
    new TracingInstrumentation({
      instrumentations: [
        ...getDefaultOtelInstrumentations(),
        new DocumentLoadInstrumentation(),
        new UserInteractionInstrumentation(),
      ],
    })
  ],
})

I found as a result of this that Faro does not get the correct values for ignoreUrls or propagateTraceHeaderCorsUrls.

Proposed solution

I think one way around this -- while maintaining backwards compatibility -- would be to allow an array of additional instrumentations to be given to Faro at initialization time, so that we don't have to re-implement getIgnoreUrls, make getIgnoreUrls public, or re-implement the entire initialize() function.

Then, options.instrumentations would clearly be an override, while options.additionalInstrumentations would be to add more tracing instrumentations that are not included by default.

Example

initializeFaro({
  instrumentations: [
    ...getWebInstrumentations(),
    new TracingInstrumentation({
      instrumentationOptions: {
         propagateTraceHeaderCorsUrls: [ ... ],
      }
      additionalInstrumentations: [
        new DocumentLoadInstrumentation(),
        new UserInteractionInstrumentation(),
      ],
    })
  ],
})

Context

This code block here is responsible for the default setup of OTEL instrumentations and configuration: https://github.com/grafana/faro-web-sdk/blob/main/packages/web-tracing/src/instrumentation.ts#L99-L108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant