Skip to content
Merged
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
10 changes: 10 additions & 0 deletions packages/fxa-settings/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,16 @@ try {
release: config.version,
sentry: {
...config.sentry,
tracesSampler: (context) => {
let rate = 0;
// We only want to sample the index page for now.
if (context.name === '/') {
if (typeof config.sentry.tracesSampleRate === 'number') {
rate = config.sentry.tracesSampleRate;
}
}
return rate;
},
},
});

Expand Down
1 change: 1 addition & 0 deletions packages/fxa-settings/src/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface Config {
dsn: string;
env: string;
sampleRate: number;
tracesSampleRate: number;
serverName: string;
clientName: string;
version: string;
Expand Down
9 changes: 9 additions & 0 deletions packages/fxa-shared/sentry/browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

import * as Sentry from '@sentry/browser';
import { SamplingContext } from '@sentry/core';
import { SentryConfigOpts } from './models/SentryConfigOpts';
import { ILogger } from '../log';
import { tagFxaName } from './tag';
Expand Down Expand Up @@ -167,12 +168,20 @@ function configure(config: SentryConfigOpts, log?: ILogger) {
disable();

const opts = buildSentryConfig(config, log);

// If tracing is configured, add the integration.
const integrations = [];
if (opts.tracesSampleRate || opts.tracesSampler) {
integrations.push(Sentry.browserTracingIntegration())
}

try {
Sentry.init({
...opts,
beforeSend: function (event: Sentry.ErrorEvent, hint?: Sentry.EventHint) {
return beforeSend(opts, event, hint);
},
integrations,
});
} catch (e) {
log.error(e);
Expand Down
1 change: 1 addition & 0 deletions packages/fxa-shared/sentry/config-builder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ export function buildSentryConfig(config: SentryConfigOpts, log: ILogger) {
serverName: config.sentry?.serverName,
fxaName: config.sentry?.clientName || config.sentry?.serverName,
tracesSampleRate: config.sentry?.tracesSampleRate,
tracesSampler: config.sentry?.tracesSampler,
};

return opts;
Expand Down
4 changes: 4 additions & 0 deletions packages/fxa-shared/sentry/models/SentryConfigOpts.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { SamplingContext } from '@sentry/core';

export type SentryConfigOpts = {
/** Name of release */
Expand All @@ -27,5 +28,8 @@ export type SentryConfigOpts = {

/** The tracing sample rate. Setting this above 0 will aso result in performance metrics being captured. */
tracesSampleRate?: number;

/** Call back to dynamically determine sampling rate. When defined, tracesSampleRate won't be used. */
tracesSampler?: (context: SamplingContext) => number | boolean;
};
};