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

feat: add web tracing to default instruments #971

Draft
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

codecapitano
Copy link
Collaborator

@codecapitano codecapitano commented Feb 14, 2025

Why

Work in process

For easy of use include the web-tracing instrumentation in the default instrumentations.

If existing users already use the web-tracing package Faro takes care of removing the default web-tracing package

This how the config changes

new way with web-tracing auto instrumentation if no customization is needed

  const faro = coreInit({
    url: `http://localhost:${env.faro.portAppReceiver}/collect`,
    apiKey: env.faro.apiKey,
    trackWebVitalsAttribution: true,
    app: {
      name: env.client.packageName,
      namespace: env.client.packageNamespace,
      version: env.package.version,
      environment: env.mode.name,
    },
  });

New way, with web-tracing auto instrumentation and additional tracing configuration

initializeFaro({
    url: `http://localhost:${env.faro.portAppReceiver}/collect`,
    apiKey: env.faro.apiKey,
    trackWebVitalsAttribution: true,
    app: {
      name: env.client.packageName,
      namespace: env.client.packageNamespace,
      version: env.package.version,
      environment: env.mode.name,
    },

    webTracingInstrumentation: {
      enabled: true, // default true
      instrumentationOptions: {
        propagateTraceHeaderCorsUrls: ['...'],
        fetchInstrumentationOptions: {
          ignoreNetworkEvents: true,
        },
      },
    },
  });

Current state

initializeFaro({
    url: `http://localhost:${env.faro.portAppReceiver}/collect`,
    apiKey: env.faro.apiKey,
    trackWebVitalsAttribution: true,
    instrumentations: [
      ...getWebInstrumentations({
        captureConsole: true,
      }),

      new TracingInstrumentation({
        instrumentationOptions: {
          propagateTraceHeaderCorsUrls: ['...'],
          fetchInstrumentationOptions: {
            ignoreNetworkEvents: true,
          },
        },
      }),
    ],
    app: {
      name: env.client.packageName,
      namespace: env.client.packageNamespace,
      version: env.package.version,
      environment: env.mode.name,
    },
  });

What

Links

Checklist

  • Tests added
  • Changelog updated
  • Documentation updated

@codecapitano codecapitano self-assigned this Feb 14, 2025
@codecapitano codecapitano changed the title Add web tracing to default instruments feat: add web tracing to default instruments Feb 14, 2025
@codecapitano codecapitano added improvement Request a change of an existing feature feature Request a new feature labels Feb 14, 2025
@codecapitano codecapitano marked this pull request as draft February 14, 2025 16:07
@codecapitano codecapitano force-pushed the add-web-tracing-to-default-instruments branch from 4fb9de7 to 0735f2b Compare February 14, 2025 16:34
@codecapitano
Copy link
Collaborator Author

codecapitano commented Feb 17, 2025

Breaking change bc customers who have no tracing today will get it by default.
May bring implications with the browser security as well where remotes will reject requests with unknown headers.

Edit:
The config has an enabled attribute which can default to false.
Bringing it up for discussion.

@@ -0,0 +1,3 @@
import { TextDecoder, TextEncoder } from 'node:util';

Object.assign(global, { TextEncoder, TextDecoder });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just so I understand why do we need to do this in a few places?

Copy link
Collaborator Author

@codecapitano codecapitano Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes this came with otel dependendencies

Comment on lines +164 to +168
if (tracingEnabled && instrumentations.find((i) => i.name === '@grafana/faro-web-tracing')) {
filteredInstrumentations = instrumentations.filter(
(instrumentation) => instrumentation.name !== TracingInstrumentation.name
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this just makes sure the old tracing instrumentation is not enabled?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This to disable the internal tracing instrumentation if the standalone web-tracing package is already in use.

Comment on lines 12 to 15
// TODO this should not be part of faro-core because it is a concern of the web-sdk package.
// We eventually will refactor all faro packages so the Config can be extended with package specific options.
// We also will remove all package specific functionality from the faro-core package.
// For time reasons and conflicting priorities, we will leave it here for now.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this part is in web-sdk - is this a leftover from copy paste?

Copy link
Collaborator Author

@codecapitano codecapitano Feb 20, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ned to adjust the text

Copy link
Collaborator

@eskirk eskirk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good just a couple questions for my own understanding

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Request a new feature improvement Request a change of an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants