Skip to content

Commit

Permalink
feat: Upgrade Sentry JS SDK to v8 (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbhiPrasad authored May 23, 2024
1 parent 31fff31 commit dc9ed6a
Show file tree
Hide file tree
Showing 6 changed files with 632 additions and 121 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
"README"
],
"dependencies": {
"@sentry/node": "7.114.0",
"@sentry/profiling-node": "7.114.0",
"@sentry/node": "^8.3.0",
"@sentry/profiling-node": "^8.3.0",
"canvas": "^2.11.2",
"dotenv": "^8.2.0",
"echarts": "5.4.0",
Expand Down
4 changes: 2 additions & 2 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#!/usr/bin/env node
// Make sure to import the Sentry SDK before importing any other modules
import './instrument';

import * as Sentry from '@sentry/node';
import dotenv from 'dotenv';
import yargs from 'yargs';

Expand All @@ -11,7 +12,6 @@ import {renderStream} from './renderStream';
import {PollingConfig} from './types';

dotenv.config();
Sentry.init({dsn: process.env.SENTRY_DSN});

const defaultPollingConfig: PollingConfig = {
/**
Expand Down
9 changes: 9 additions & 0 deletions src/instrument.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import * as Sentry from '@sentry/node';
import {nodeProfilingIntegration} from '@sentry/profiling-node';

Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [nodeProfilingIntegration()],
profilesSampleRate: 1,
tracesSampleRate: 1,
});
21 changes: 3 additions & 18 deletions src/renderServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import {performance} from 'node:perf_hooks';

import * as Sentry from '@sentry/node';
import {ProfilingIntegration} from '@sentry/profiling-node';
import express from 'express';

import {ConfigService} from './config';
Expand All @@ -17,23 +16,8 @@ export function renderServer(config: ConfigService) {
const app = express();
const renderRoutes = express.Router();

Sentry.init({
dsn: process.env.SENTRY_DSN,
integrations: [
new Sentry.Integrations.Http({tracing: true}),
new Sentry.Integrations.Express({router: renderRoutes}),
new ProfilingIntegration(),
],
profilesSampleRate: 1,
tracesSampleRate: 1,
_experiments: {
metricsAggregator: true,
},
});

renderRoutes.use(express.json({limit: '20mb'}));
renderRoutes.use(Sentry.Handlers.requestHandler());
renderRoutes.use(Sentry.Handlers.tracingHandler());

renderRoutes.use((req, resp) => {
if (!config.isLoaded) {
resp.status(503).send();
Expand Down Expand Up @@ -91,7 +75,6 @@ export function renderServer(config: ConfigService) {
Sentry.metrics.increment('render.count');
Sentry.metrics.distribution('render.time', time);
});
renderRoutes.use(Sentry.Handlers.errorHandler());

app.post('/render', renderRoutes);

Expand All @@ -105,5 +88,7 @@ export function renderServer(config: ConfigService) {
: resp.status(503).send('NOT CONFIGURED')
);

Sentry.setupExpressErrorHandler(app);

return app;
}
9 changes: 8 additions & 1 deletion tests/renderStream.spec.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,19 @@
import type {EChartsOption} from 'echarts';
import fs from 'node:fs';
import fs, {readFile} from 'node:fs';

import {ConfigService} from 'app/config';
import {renderStream} from 'app/renderStream';
import {RenderData} from 'app/types';

jest.mock('node:fs');

jest.mock('node:fs', () => {
return {
...jest.requireActual('node:fs'),
readFile: jest.fn(),
};
});

describe('renderStream', () => {
it('can render graphs given a valid config and render data', async () => {
const config = new ConfigService('./example');
Expand Down
Loading

0 comments on commit dc9ed6a

Please sign in to comment.