This repository has been archived by the owner on Aug 14, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 224
/
gatsby-node.js
84 lines (73 loc) · 2.18 KB
/
gatsby-node.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
const Sentry = require('@sentry/node');
const Profiling = require('@sentry/profiling-node');
const activeEnv = process.env.GATSBY_ENV || process.env.NODE_ENV || 'development';
Sentry.init({
dsn:
process.env.SENTRY_DSN ||
'https://[email protected]/5266138',
environment: activeEnv,
tracesSampleRate: activeEnv === 'development' ? 0 : 1,
profilesSampleRate: activeEnv === 'development' ? 0 : 1, // Set profiling sampling rate.
integrations: [new Profiling.ProfilingIntegration()],
});
exports.onCreateNode = require('./src/gatsby/onCreateNode').default;
exports.onCreateWebpackConfig = require('./src/gatsby/onCreateWebpackConfig').default;
exports.createPages = require('./src/gatsby/createPages').default;
exports.createSchemaCustomization =
require('./src/gatsby/createSchemaCustomization').default;
Sentry.configureScope(scope => {
const id = process.env.GITHUB_RUN_ID;
if (id) {
scope.setUser({id});
}
});
function startFromPrevTransaction(newTransactionContext) {
const oldTransaction = Sentry.getCurrentHub()?.getScope()?.getTransaction();
let oldTransactionTraceParent;
if (oldTransaction) {
oldTransactionTraceParent = {
traceId: oldTransaction.traceId,
parentSpanId: oldTransaction.spanId,
sampled: oldTransaction.sampled,
};
oldTransaction.finish();
}
const transaction = Sentry.startTransaction({
...newTransactionContext,
...oldTransactionTraceParent,
tags: {
ref: process.env.GITHUB_BASE_REF,
sha: process.env.GITHUB_SHA,
job: process.env.GITHUB_JOB,
run: process.env.GITHUB_RUN_ID,
},
});
Sentry.configureScope(scope => {
scope.setSpan(transaction);
});
}
exports.onPreInit = () => {
startFromPrevTransaction({
op: 'build',
name: 'Init',
});
};
exports.onPreBootstrap = () => {
startFromPrevTransaction({
op: 'build',
name: 'Bootstrap',
});
};
exports.onPreBuild = () => {
startFromPrevTransaction({
op: 'build',
name: 'Build',
});
};
exports.onPostBuild = () => {
const transaction = Sentry.getCurrentHub()?.getScope()?.getTransaction();
if (transaction) {
transaction.finish();
}
Sentry.flush(7000);
};