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(web-sdk): add webVitalsInstrumentation.trackAttribution, enable by default #991

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@

- Feature (`@grafana/faro-web-sdk`): Provide a `webVitalsInstrumentation.reportAllChanges` option to report
all changes for web vitals (#981)
- feat (`@grafana/faro-web-sdk`): Enhance user meta properties to align with OTEL semantic
- Feature (`@grafana/faro-web-sdk`): Provide a `webVitalsInstrumentation.trackAttribution` option to track
web vitals attribution (#991)
- Feature (`@grafana/faro-web-sdk`): Change `trackWebVitalsAttribution` default value to true (#991)
- Feature (`@grafana/faro-web-sdk`): Enhance user meta properties to align with OTEL semantic
conventions for user attributes (#990)
- Chore (`@grafana/faro-web-tracing`): Add user attributes to spans (#990)

Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/config/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ export interface Config<P = APIEvent> {
trackResources?: boolean;

/**
* Track web vitals attribution data (default: false)
* Track web vitals attribution data (default: true)
*/
trackWebVitalsAttribution?: boolean;

Expand All @@ -178,6 +178,13 @@ export interface Config<P = APIEvent> {
* for measuring these metrics in production.
*/
reportAllChanges?: boolean;

/**
* Track web vitals attribution data (default: true)
*
* Functionally the same as setting `trackWebVitalsAttribution` to true.
*/
trackAttribution?: boolean;
};

/**
Expand Down
16 changes: 16 additions & 0 deletions packages/web-sdk/src/config/makeCoreConfig.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,22 @@ describe('config', () => {
expect(config?.webVitalsInstrumentation?.reportAllChanges).toBe(true);
});

it('enables web vitals feature when webVitalsInstrumentation.trackAttribution is true', () => {
const browserConfig = {
url: 'http://example.com/my-collector',
app: {},
webVitalsInstrumentation: {
reportAllChanges: true,
trackAttribution: true,
},
};
const config = makeCoreConfig(browserConfig);

expect(config).toBeTruthy();
expect(config?.webVitalsInstrumentation?.reportAllChanges).toBe(true);
expect(config?.webVitalsInstrumentation?.trackAttribution).toBe(true);
});

it('merges configured urls with default URLs into ignoreUrls list', () => {
const browserConfig = {
url: 'http://example.com/my-collector',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('WebVitals Instrumentation', () => {
jest.clearAllMocks();
});

it('load WebVitalsBasic by default', () => {
it('load WebVitalsWithAttribution by default', () => {
const transport = new MockTransport();

initializeFaro(
Expand All @@ -23,16 +23,33 @@ describe('WebVitals Instrumentation', () => {
})
);

expect(WebVitalsBasic).toHaveBeenCalledTimes(0);
expect(WebVitalsWithAttribution).toHaveBeenCalledTimes(1);
});

it('load WebVitalsBasic when trackWebVitalAttribution is false', () => {
const transport = new MockTransport();

initializeFaro(
mockConfig({
trackWebVitalsAttribution: false,
transports: [transport],
instrumentations: [new WebVitalsInstrumentation()],
})
);

expect(WebVitalsBasic).toHaveBeenCalledTimes(1);
expect(WebVitalsWithAttribution).toHaveBeenCalledTimes(0);
});

it('load WebVitalsWithAttribution when trackWebVitalAttribution is true', () => {
it('load WebVitalsWithAttribution when webVitalsInstrumentation.trackAttribution is true', () => {
const transport = new MockTransport();

initializeFaro(
mockConfig({
trackWebVitalsAttribution: true,
webVitalsInstrumentation: {
trackAttribution: true,
},
transports: [transport],
instrumentations: [new WebVitalsInstrumentation()],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@ export class WebVitalsInstrumentation extends BaseInstrumentation {
}

private intializeWebVitalsInstrumentation() {
if (this.config?.trackWebVitalsAttribution) {
return new WebVitalsWithAttribution(this.api.pushMeasurement, this.config.webVitalsInstrumentation);
if (
this.config?.trackWebVitalsAttribution === false ||
this.config?.webVitalsInstrumentation?.trackAttribution === false
Comment on lines +18 to +19
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's initialize default settings in makeCoreConfig().
It's the central hub for everything config related and we already add all the default values there.

) {
return new WebVitalsBasic(this.api.pushMeasurement, this.config.webVitalsInstrumentation);
}
return new WebVitalsBasic(this.api.pushMeasurement, this.config.webVitalsInstrumentation);
return new WebVitalsWithAttribution(this.api.pushMeasurement, this.config.webVitalsInstrumentation);
}
}