Skip to content

Commit

Permalink
refact: setup sentry profiling
Browse files Browse the repository at this point in the history
  • Loading branch information
kewitz committed Dec 20, 2024
1 parent 8bff6ad commit 9856fc4
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 11 deletions.
1 change: 1 addition & 0 deletions config/custom-environment-variables.json
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@
"sentry": {
"dsn": "SENTRY_DSN",
"tracesSampleRate": "SENTRY_TRACES_SAMPLE_RATE",
"profilesSampleRate": "SENTRY_PROFILES_SAMPLE_RATE",
"minExecutionTimeToSample": "SENTRY_MIN_EXECUTION_TIME_TO_SAMPLE"
},
"ledger": {
Expand Down
1 change: 1 addition & 0 deletions config/default.json
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@
},
"sentry": {
"tracesSampleRate": 0,
"profilesSampleRate": 0,
"minExecutionTimeToSample": 800
},
"ledger": {
Expand Down
3 changes: 2 additions & 1 deletion config/production.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"fetchHostTransactionsCsv": true
},
"sentry": {
"tracesSampleRate": 0.01
"tracesSampleRate": 0.01,
"profilesSampleRate": 0.02
},
"graphql": {
"cache": {
Expand Down
3 changes: 2 additions & 1 deletion config/staging.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@
"fetchTransactionsReceipts": true
},
"sentry": {
"tracesSampleRate": 0.01
"tracesSampleRate": 0.01,
"profilesSampleRate": 0.02
},
"restService": {
"fetchCollectiveTransactionsCsv": true,
Expand Down
52 changes: 45 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
"@peculiar/asn1-schema": "2.3.13",
"@peculiar/asn1-x509": "2.3.13",
"@sentry/node": "7.119.2",
"@sentry/profiling-node": "7.120.2",
"@sentry/types": "7.119.2",
"@shopify/address": "4.3.0",
"@simplewebauthn/server": "11.0.0",
Expand Down
9 changes: 7 additions & 2 deletions server/lib/sentry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ import '../env';

import { ApolloServerPlugin } from '@apollo/server';
import * as Sentry from '@sentry/node';
import { nodeProfilingIntegration } from '@sentry/profiling-node';
import type { SeverityLevel } from '@sentry/types';
import axios, { AxiosError } from 'axios';
import config from 'config';
import { cloneDeep, get, isEmpty, isEqual, pick } from 'lodash';
import { cloneDeep, compact, get, isEmpty, isEqual, pick } from 'lodash';

import FEATURE from '../constants/feature';
import { User } from '../models';
Expand All @@ -22,6 +23,7 @@ import { safeJsonStringify, sanitizeObjectForJSON } from './safe-json-stringify'
import * as utils from './utils';

const TRACES_SAMPLE_RATE = parseFloat(config.sentry.tracesSampleRate) || 0;
const PROFILES_SAMPLE_RATE = parseFloat(config.sentry.profilesSampleRate) || 0;
const MIN_EXECUTION_TIME_TO_SAMPLE = parseInt(config.sentry.minExecutionTimeToSample);

const checkIfSentryConfigured = () => Boolean(config.sentry?.dsn);
Expand Down Expand Up @@ -64,6 +66,7 @@ Sentry.init({
},
dsn: config.sentry.dsn,
environment: config.env,
integrations: compact([TRACES_SAMPLE_RATE > 0 && nodeProfilingIntegration()]),
attachStacktrace: true,
enabled: config.env !== 'test',
tracesSampler: samplingContext => {
Expand All @@ -75,10 +78,12 @@ Sentry.init({
return TRACES_SAMPLE_RATE;
}
},
// Relative to tracesSampler
profilesSampleRate: PROFILES_SAMPLE_RATE,
});

if (checkIfSentryConfigured()) {
logger.info('Initializing Sentry');
logger.info(`Initializing Sentry in ${config.env} environment `);

// Catch all errors that haven't been caught anywhere else
process
Expand Down

0 comments on commit 9856fc4

Please sign in to comment.