Skip to content

Commit

Permalink
[backend] Improve pyroscope instrumentation to use source mapping
Browse files Browse the repository at this point in the history
  • Loading branch information
richard-julien committed Jan 11, 2025
1 parent af13f58 commit 989019e
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 11 deletions.
6 changes: 6 additions & 0 deletions opencti-platform/opencti-graphql/builder/dev/dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ esbuild.build({
to: ['./prebuilds'],
}
}),
copy({
assets: {
from: ['./node_modules/source-map/lib/mappings.wasm'],
to: ['.'],
}
}),
],
entryPoints: [
'src/back.js',
Expand Down
6 changes: 6 additions & 0 deletions opencti-platform/opencti-graphql/builder/prod/prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ esbuild.build({
to: ['./prebuilds'],
}
}),
copy({
assets: {
from: ['./node_modules/source-map/lib/mappings.wasm'],
to: ['.'],
}
}),
],
entryPoints: [
'src/back.js',
Expand Down
1 change: 1 addition & 0 deletions opencti-platform/opencti-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
"cookie": "0.7.2",
"cross-fetch": "4.0.0",
"jose": "5.9.6",
"source-map": "0.7.4",
"json5": "2.2.3",
"lodash": "4.17.21",
"@xmldom/xmldom": "0.8.10",
Expand Down
12 changes: 9 additions & 3 deletions opencti-platform/opencti-graphql/src/instrumentation.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import nconf from 'nconf';

import { SourceMapper } from '@datadog/pprof';
import { booleanConf, logApp } from './config/conf';

const isPyroscopeEnable = booleanConf('app:telemetry:pyroscope:enabled', false);
Expand All @@ -8,10 +10,14 @@ if (isPyroscopeEnable) {
const Pyroscope = require('@pyroscope/nodejs');
const node = nconf.get('app:telemetry:pyroscope:identifier') ?? 'opencti';
const exporter = nconf.get('app:telemetry:pyroscope:exporter');
Pyroscope.init({ serverAddress: exporter, appName: node });
Pyroscope.start();
SourceMapper.create(['.']).then((sourceMapper) => {
Pyroscope.init({ serverAddress: exporter, appName: node, sourceMapper });
Pyroscope.start();
}).catch((err) => {
logApp.error('[OPENCTI] Error loading Pyroscope source mapper', { cause: err });
});
logApp.info('[OPENCTI] Pyroscope plugin successfully loaded.');
} catch (err) {
logApp.error('[OPENCTI] Error loading Pyroscope', { cause: err.message });
logApp.error('[OPENCTI] Error loading Pyroscope', { cause: err });
}
}
9 changes: 1 addition & 8 deletions opencti-platform/opencti-graphql/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13261,14 +13261,7 @@ __metadata:
languageName: node
linkType: hard

"source-map@npm:^0.6.0":
version: 0.6.1
resolution: "source-map@npm:0.6.1"
checksum: 10/59ef7462f1c29d502b3057e822cdbdae0b0e565302c4dd1a95e11e793d8d9d62006cdc10e0fd99163ca33ff2071360cf50ee13f90440806e7ed57d81cba2f7ff
languageName: node
linkType: hard

"source-map@npm:^0.7.3, source-map@npm:^0.7.4":
"source-map@npm:0.7.4":
version: 0.7.4
resolution: "source-map@npm:0.7.4"
checksum: 10/a0f7c9b797eda93139842fd28648e868a9a03ea0ad0d9fa6602a0c1f17b7fb6a7dcca00c144476cccaeaae5042e99a285723b1a201e844ad67221bf5d428f1dc
Expand Down

0 comments on commit 989019e

Please sign in to comment.