зеркало из https://github.com/mozilla/fxa.git
deps(sentry): upgrade Sentry to version 8
Because: - Sentry 8 is the latest version This commit: - deletes some integration code since Sentry does it automatically - updates code to use the Sentry 8 API - updates a few proxyquire calls because they were cause module not found errors in CI
This commit is contained in:
Родитель
b327092b7e
Коммит
83dc649b52
|
@ -49,7 +49,11 @@ export const _Sentry = {
|
|||
* Modified error object data
|
||||
* @private
|
||||
*/
|
||||
function beforeSend(opts: SentryConfigOpts, event: Sentry.Event, hint?: any) {
|
||||
function beforeSend(
|
||||
opts: SentryConfigOpts,
|
||||
event: Sentry.ErrorEvent,
|
||||
hint?: Sentry.EventHint
|
||||
) {
|
||||
if (sentryEnabled === false) {
|
||||
return null;
|
||||
}
|
||||
|
@ -166,12 +170,7 @@ function configure(config: SentryConfigOpts, log?: Logger) {
|
|||
try {
|
||||
Sentry.init({
|
||||
...opts,
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration({
|
||||
enableInp: true,
|
||||
}),
|
||||
],
|
||||
beforeSend: function (event: Sentry.Event, hint?: any) {
|
||||
beforeSend: function (event: Sentry.ErrorEvent, hint: Sentry.EventHint) {
|
||||
return beforeSend(opts, event, hint);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -12,7 +12,6 @@ import {
|
|||
NestInterceptor,
|
||||
} from '@nestjs/common';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { Transaction } from '@sentry/types';
|
||||
|
||||
import { ignoreError, processException } from '../reporting';
|
||||
|
||||
|
@ -22,11 +21,13 @@ export class SentryInterceptor implements NestInterceptor {
|
|||
// If there is http context request start a transaction for it. Note that this will not
|
||||
// pick up graphql queries
|
||||
const req = context.switchToHttp().getRequest();
|
||||
let transaction: Transaction;
|
||||
let transaction: Sentry.Span;
|
||||
|
||||
if (req) {
|
||||
transaction = Sentry.startTransaction({
|
||||
transaction = Sentry.startInactiveSpan({
|
||||
op: 'nestjs.http',
|
||||
name: `${req.method} ${req.path}`,
|
||||
forceTransaction: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -42,7 +43,7 @@ export class SentryInterceptor implements NestInterceptor {
|
|||
},
|
||||
}),
|
||||
finalize(() => {
|
||||
transaction?.finish();
|
||||
transaction?.end();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -22,7 +22,6 @@ import {
|
|||
} from '@apollo/server';
|
||||
import { Plugin } from '@nestjs/apollo';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { Transaction } from '@sentry/types';
|
||||
|
||||
import {
|
||||
ExtraContext,
|
||||
|
@ -33,14 +32,15 @@ import { Inject } from '@nestjs/common';
|
|||
import { MozLoggerService } from '@fxa/shared/mozlog';
|
||||
|
||||
interface Context extends BaseContext {
|
||||
transaction: Transaction;
|
||||
transaction: Sentry.Span;
|
||||
request: Request;
|
||||
}
|
||||
|
||||
export async function createContext(ctx: any): Promise<Context> {
|
||||
const transaction = Sentry.startTransaction({
|
||||
const transaction = Sentry.startInactiveSpan({
|
||||
op: 'gql',
|
||||
name: 'GraphQLTransaction',
|
||||
forceTransaction: true,
|
||||
});
|
||||
return { request: ctx.req, transaction };
|
||||
}
|
||||
|
@ -57,7 +57,7 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
|
|||
|
||||
if (request.operationName != null) {
|
||||
try {
|
||||
contextValue.transaction.setName(request.operationName);
|
||||
contextValue.transaction.updateName(request.operationName);
|
||||
} catch (err) {
|
||||
log.error('sentry-plugin', err);
|
||||
}
|
||||
|
@ -66,7 +66,7 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
|
|||
return {
|
||||
async willSendResponse({ contextValue }) {
|
||||
try {
|
||||
contextValue.transaction.finish();
|
||||
contextValue.transaction.end();
|
||||
} catch (err) {
|
||||
log.error('sentry-plugin', err);
|
||||
}
|
||||
|
@ -75,18 +75,19 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
|
|||
async executionDidStart() {
|
||||
return {
|
||||
willResolveField({ contextValue, info }) {
|
||||
let span: any;
|
||||
let span: Sentry.Span;
|
||||
try {
|
||||
span = contextValue.transaction.startChild({
|
||||
span = Sentry.startInactiveSpan({
|
||||
op: 'resolver',
|
||||
description: `${info.parentType.name}.${info.fieldName}`,
|
||||
name: `${info.parentType.name}.${info.fieldName}`,
|
||||
scope: contextValue.transaction,
|
||||
});
|
||||
} catch (err) {
|
||||
log.error('sentry-plugin', err);
|
||||
}
|
||||
|
||||
return () => {
|
||||
span?.finish();
|
||||
span?.end();
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -39,11 +39,6 @@ export function initSentryForNextjsClient(
|
|||
try {
|
||||
Sentry.init({
|
||||
...opts,
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration({
|
||||
enableInp: true,
|
||||
}),
|
||||
],
|
||||
beforeSend: function (event: Sentry.ErrorEvent) {
|
||||
return beforeSend(sentryEnabled, opts, event);
|
||||
},
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { ErrorEvent } from '@sentry/types';
|
||||
import { ExtraErrorData } from '@sentry/integrations';
|
||||
import { extraErrorDataIntegration } from '@sentry/node';
|
||||
import { SentryConfigOpts } from './models/SentryConfigOpts';
|
||||
import { buildSentryConfig } from './config-builder';
|
||||
import { tagFxaName } from './reporting';
|
||||
|
@ -39,8 +39,7 @@ export function initSentry(config: InitSentryOpts, log: Logger) {
|
|||
};
|
||||
|
||||
const integrations = [
|
||||
// Default
|
||||
new ExtraErrorData({ depth: 5 }),
|
||||
extraErrorDataIntegration({ depth: 5 }),
|
||||
|
||||
// Custom Integrations
|
||||
...(config.integrations || []),
|
||||
|
@ -49,7 +48,6 @@ export function initSentry(config: InitSentryOpts, log: Logger) {
|
|||
try {
|
||||
Sentry.init({
|
||||
// Defaults Options
|
||||
instrumenter: 'otel',
|
||||
normalizeDepth: 6,
|
||||
maxValueLength: 500,
|
||||
|
||||
|
|
|
@ -167,11 +167,11 @@ export function reportRequestException(
|
|||
}
|
||||
|
||||
Sentry.withScope((scope: Sentry.Scope) => {
|
||||
scope.addEventProcessor((event: Sentry.Event) => {
|
||||
scope.addEventProcessor((event) => {
|
||||
if (request) {
|
||||
const sentryEvent = Sentry.Handlers.parseRequest(event, request);
|
||||
sentryEvent.level = 'error';
|
||||
return sentryEvent;
|
||||
event.request = Sentry.extractRequestData(request);
|
||||
event.level = 'error';
|
||||
return event;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
|
|
@ -76,11 +76,10 @@
|
|||
"@paypal/react-paypal-js": "^8.7.0",
|
||||
"@radix-ui/react-form": "^0.0.3",
|
||||
"@radix-ui/react-tooltip": "^1.1.2",
|
||||
"@sentry/browser": "^7.113.0",
|
||||
"@sentry/integrations": "^7.113.0",
|
||||
"@sentry/nextjs": "^8",
|
||||
"@sentry/node": "^7.113.0",
|
||||
"@sentry/opentelemetry-node": "^7.113.0",
|
||||
"@sentry/browser": "^8.28.0",
|
||||
"@sentry/nextjs": "^8.28.0",
|
||||
"@sentry/node": "^8.28.0",
|
||||
"@sentry/opentelemetry": "^8.28.0",
|
||||
"@swc/helpers": "0.5.11",
|
||||
"@type-cacheable/core": "^14.1.0",
|
||||
"@type-cacheable/ioredis-adapter": "^10.0.4",
|
||||
|
|
|
@ -47,7 +47,7 @@ if (sentryConfig.dsn) {
|
|||
return event;
|
||||
},
|
||||
});
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
Sentry.setupExpressErrorHandler(app);
|
||||
}
|
||||
|
||||
var verifier = new CCVerifier({
|
||||
|
|
|
@ -30,9 +30,6 @@ logger.info('version', { version: version });
|
|||
|
||||
// Initialize Sentry
|
||||
const sentryConfig = config.get('sentry');
|
||||
if (sentryConfig.dsn) {
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
}
|
||||
|
||||
app.use(
|
||||
helmet.frameguard({
|
||||
|
@ -145,7 +142,7 @@ if (proxyUrl) {
|
|||
|
||||
// Send errors to sentry.
|
||||
if (sentryConfig.dsn) {
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
Sentry.setupExpressErrorHandler(app);
|
||||
}
|
||||
|
||||
export default app;
|
||||
|
|
|
@ -21,7 +21,7 @@ initMonitoring({
|
|||
...config.getProperties(),
|
||||
release: version,
|
||||
eventFilters: [filterSentryEvent],
|
||||
integrations: [new Sentry.Integrations.LinkedErrors({ key: 'jse_cause' })],
|
||||
integrations: [Sentry.linkedErrorsIntegration({ key: 'jse_cause' })],
|
||||
},
|
||||
});
|
||||
|
||||
|
|
|
@ -34,11 +34,8 @@ function reportSentryError(err, request) {
|
|||
|
||||
Sentry.withScope((scope) => {
|
||||
if (request) {
|
||||
scope.addEventProcessor((_sentryEvent) => {
|
||||
const sentryEvent = Sentry.Handlers.parseRequest(
|
||||
_sentryEvent,
|
||||
request.raw.req
|
||||
);
|
||||
scope.addEventProcessor((sentryEvent) => {
|
||||
sentryEvent.request = Sentry.extractRequestData(request.raw.req);
|
||||
sentryEvent.level = 'error';
|
||||
return sentryEvent;
|
||||
});
|
||||
|
@ -106,9 +103,7 @@ function reportSentryError(err, request) {
|
|||
|
||||
async function configureSentry(server, config, processName = 'key_server') {
|
||||
if (config.sentry.dsn) {
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setTag('process', processName);
|
||||
});
|
||||
Sentry.getCurrentScope().setTag('process', processName);
|
||||
|
||||
if (!server) {
|
||||
return;
|
||||
|
@ -120,6 +115,7 @@ async function configureSentry(server, config, processName = 'key_server') {
|
|||
method(request, h) {
|
||||
request.sentryScope = new Sentry.Scope();
|
||||
|
||||
/**
|
||||
// Make a transaction per request so we can get performance monitoring. There are
|
||||
// some limitations to this approach, and distributed tracing will be off due to
|
||||
// hapi's architecture.
|
||||
|
@ -128,23 +124,17 @@ async function configureSentry(server, config, processName = 'key_server') {
|
|||
// looks like there might be some other solutions that are more complex, but would work
|
||||
// with hapi and distributed tracing.
|
||||
//
|
||||
const transaction = Sentry.startTransaction(
|
||||
{
|
||||
op: 'auth-server',
|
||||
name: `${request.method.toUpperCase()} ${request.path}`,
|
||||
},
|
||||
{
|
||||
request: Sentry.Handlers.extractRequestData(request.raw.req),
|
||||
}
|
||||
);
|
||||
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setSpan(transaction);
|
||||
const transaction = Sentry.startInactiveSpan({
|
||||
op: 'auth-server',
|
||||
name: `${request.method.toUpperCase()} ${request.path}`,
|
||||
forceTransaction: true,
|
||||
request: Sentry.extractRequestData(request.raw.req),
|
||||
});
|
||||
|
||||
request.app.sentry = {
|
||||
transaction,
|
||||
};
|
||||
//*/
|
||||
|
||||
return h.continue;
|
||||
},
|
||||
|
|
|
@ -2,12 +2,13 @@
|
|||
* 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/. */
|
||||
|
||||
const path = require('path');
|
||||
const { assert } = require('chai');
|
||||
const proxyquire = require('proxyquire');
|
||||
const mocks = require('../../lib/mocks');
|
||||
const keys = require('../../../lib/oauth/keys');
|
||||
|
||||
const routeModulePath = '../../../lib/routes/oauth/jwks';
|
||||
const routeModulePath = path.join(__dirname, '../../../lib/routes/oauth/jwks');
|
||||
var dependencies = mocks.require(
|
||||
[{ path: '../../oauth/keys' }],
|
||||
routeModulePath,
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
const { assert } = require('chai');
|
||||
const buf = require('buf').hex;
|
||||
const hex = require('buf').to.hex;
|
||||
const path = require('path');
|
||||
const proxyquire = require('proxyquire');
|
||||
const sinon = require('sinon');
|
||||
|
||||
|
@ -23,7 +24,8 @@ const CODE_WITHOUT_KEYS = 'f0f0f0';
|
|||
const mockDb = { touchSessionToken: sinon.stub() };
|
||||
const mockStatsD = { increment: sinon.stub() };
|
||||
const mockGlean = { oauth: { tokenCreated: sinon.stub() } };
|
||||
const tokenRoutes = proxyquire('../../../lib/routes/oauth/token', {
|
||||
const tokenRoutePath = path.join(__dirname, '../../../lib/routes/oauth/token');
|
||||
const tokenRoutes = proxyquire(tokenRoutePath, {
|
||||
'../../oauth/assertion': async () => true,
|
||||
'../../oauth/client': {
|
||||
authenticateClient: (_, params) => ({
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
* 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/. */
|
||||
|
||||
const path = require('path');
|
||||
const { assert } = require('chai');
|
||||
const proxyquire = require('proxyquire');
|
||||
const sinon = require('sinon');
|
||||
|
@ -50,7 +51,7 @@ describe('/verify POST', () => {
|
|||
};
|
||||
|
||||
route = proxyquire(
|
||||
'../../../lib/routes/oauth/verify',
|
||||
path.join(__dirname, '../../../lib/routes/oauth/verify'),
|
||||
dependencies
|
||||
)({ log: mocks.log, glean: mocks.glean });
|
||||
});
|
||||
|
|
|
@ -134,12 +134,6 @@ function SentryMetrics(config) {
|
|||
const opts = buildSentryConfig(config, this._logger);
|
||||
Sentry.init({
|
||||
...opts,
|
||||
instrumenter: 'otel',
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration({
|
||||
enableInp: true,
|
||||
}),
|
||||
],
|
||||
beforeSend(event) {
|
||||
event = tagFxaName(event, opts.clientName);
|
||||
event = beforeSend(event);
|
||||
|
|
|
@ -6,6 +6,8 @@
|
|||
|
||||
'use strict';
|
||||
|
||||
const sentry = require('../lib/sentry');
|
||||
|
||||
// setup version first for the rest of the modules
|
||||
const loggerFactory = require('../lib/logging/log');
|
||||
const logger = loggerFactory('server.main');
|
||||
|
@ -30,7 +32,6 @@ const https = require('https');
|
|||
const path = require('path');
|
||||
const serveStatic = require('serve-static');
|
||||
|
||||
const sentry = require('../lib/sentry');
|
||||
const statsd = require('../lib/statsd');
|
||||
const { cors, routing } = require('fxa-shared/express').express();
|
||||
const {
|
||||
|
@ -105,9 +106,6 @@ function makeApp() {
|
|||
app.set('view engine', 'html');
|
||||
app.set('views', PAGE_TEMPLATE_DIRECTORY);
|
||||
|
||||
// The request handler must be the first item
|
||||
app.use(sentry.sentryModule.Handlers.requestHandler());
|
||||
|
||||
// i18n adds metadata to a request to help
|
||||
// with translating templates on the server.
|
||||
app.use(i18n);
|
||||
|
@ -237,17 +235,15 @@ function makeApp() {
|
|||
});
|
||||
|
||||
// The sentry error handler must be before any other error middleware
|
||||
app.use(
|
||||
sentry.sentryModule.Handlers.errorHandler({
|
||||
shouldHandleError(error) {
|
||||
const success = tryCaptureValidationError(error);
|
||||
sentry.sentryModule.setupExpressErrorHandler(app, {
|
||||
shouldHandleError(error) {
|
||||
const success = tryCaptureValidationError(error);
|
||||
|
||||
// If the validation was explicitly captured, we return false. Otherwise the
|
||||
// error is reported twice.
|
||||
return !success;
|
||||
},
|
||||
})
|
||||
);
|
||||
// If the validation was explicitly captured, we return false. Otherwise the
|
||||
// error is reported twice.
|
||||
return !success;
|
||||
},
|
||||
});
|
||||
|
||||
// log and capture any errors
|
||||
app.use((err, req, res, next) => {
|
||||
|
|
|
@ -73,7 +73,7 @@ if (config.get('sentry.dsn')) {
|
|||
event = tagFxaName(event, opts.serverName);
|
||||
return event;
|
||||
},
|
||||
integrations: [new Sentry.Integrations.LinkedErrors({ key: 'jse_cause' })],
|
||||
integrations: [Sentry.linkedErrorsIntegration({ key: 'jse_cause' })],
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,6 @@ initMonitoring({
|
|||
config: {
|
||||
...config,
|
||||
release: version,
|
||||
integrations: [new Sentry.Integrations.LinkedErrors({ key: 'jse_cause' })],
|
||||
integrations: [Sentry.linkedErrorsIntegration({ key: 'jse_cause' })],
|
||||
},
|
||||
});
|
||||
|
|
|
@ -8,9 +8,7 @@ const Hoek = require('@hapi/hoek');
|
|||
const Sentry = require('@sentry/node');
|
||||
|
||||
async function configureSentry(server, config, log) {
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setTag('process', 'customs_server');
|
||||
});
|
||||
Sentry.getCurrentScope().setTag('process', 'customs_server');
|
||||
|
||||
// Attach a new Sentry scope to the request for breadcrumbs/tags/extras
|
||||
server.ext({
|
||||
|
@ -26,18 +24,11 @@ async function configureSentry(server, config, log) {
|
|||
// looks like there might be some other solutions that are more complex, but would work
|
||||
// with hapi and distributed tracing.
|
||||
//
|
||||
const transaction = Sentry.startTransaction(
|
||||
{
|
||||
op: 'auth-server',
|
||||
name: `${request.method.toUpperCase()} ${request.path}`,
|
||||
},
|
||||
{
|
||||
request: Sentry.Handlers.extractRequestData(request.raw.req),
|
||||
}
|
||||
);
|
||||
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setSpan(transaction);
|
||||
const transaction = Sentry.startInactiveSpan({
|
||||
op: 'auth-server',
|
||||
name: `${request.method.toUpperCase()} ${request.path}`,
|
||||
forceTransaction: true,
|
||||
request: Sentry.extractRequestData(request.raw.req),
|
||||
});
|
||||
|
||||
request.app.sentry = {
|
||||
|
@ -62,11 +53,8 @@ async function configureSentry(server, config, log) {
|
|||
}
|
||||
}
|
||||
Sentry.withScope((scope) => {
|
||||
scope.addEventProcessor((_sentryEvent) => {
|
||||
const sentryEvent = Sentry.Handlers.parseRequest(
|
||||
_sentryEvent,
|
||||
request.raw.req
|
||||
);
|
||||
scope.addEventProcessor((sentryEvent) => {
|
||||
sentryEvent.request = Sentry.extractRequestData(request.raw.req);
|
||||
sentryEvent.level = 'error';
|
||||
return sentryEvent;
|
||||
});
|
||||
|
|
|
@ -16,6 +16,6 @@ initMonitoring({
|
|||
config: {
|
||||
...config,
|
||||
release: version,
|
||||
integrations: [new Sentry.Integrations.LinkedErrors({ key: 'jse_cause' })],
|
||||
integrations: [Sentry.linkedErrorsIntegration({ key: 'jse_cause' })],
|
||||
},
|
||||
});
|
||||
|
|
|
@ -114,9 +114,6 @@ module.exports = () => {
|
|||
app.disable('x-powered-by');
|
||||
|
||||
const sentryConfig = config.get('sentry');
|
||||
if (sentryConfig.dsn) {
|
||||
app.use(Sentry.Handlers.requestHandler());
|
||||
}
|
||||
|
||||
const hstsEnabled = config.get('hstsEnabled');
|
||||
if (hstsEnabled) {
|
||||
|
@ -224,7 +221,13 @@ module.exports = () => {
|
|||
return result;
|
||||
}
|
||||
|
||||
function injectHtmlConfig(html, config, featureFlags, paypalCspNonce, gaCspNonce) {
|
||||
function injectHtmlConfig(
|
||||
html,
|
||||
config,
|
||||
featureFlags,
|
||||
paypalCspNonce,
|
||||
gaCspNonce
|
||||
) {
|
||||
return injectMetaContent(html, {
|
||||
__SERVER_CONFIG__: config,
|
||||
__FEATURE_FLAGS__: featureFlags,
|
||||
|
@ -309,7 +312,7 @@ module.exports = () => {
|
|||
|
||||
if (sentryConfig.dsn) {
|
||||
// Send errors to sentry.
|
||||
app.use(Sentry.Handlers.errorHandler());
|
||||
Sentry.setupExpressErrorHandler(app);
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
|
@ -140,11 +140,6 @@ SentryMetrics.prototype = {
|
|||
|
||||
Sentry.init({
|
||||
...opts,
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration({
|
||||
enableInp: true,
|
||||
}),
|
||||
],
|
||||
beforeSend(event) {
|
||||
event = tagCriticalEvent(event);
|
||||
event = tagFxaName(event, opts.clientName);
|
||||
|
@ -181,7 +176,7 @@ SentryMetrics.prototype = {
|
|||
* @param {*} severity Enum passed to Sentry.captureMessage to set severity level
|
||||
*/
|
||||
captureMessage(message, contextKey, context, severity) {
|
||||
Sentry.withScope(function(scope) {
|
||||
Sentry.withScope(function (scope) {
|
||||
scope.setContext(contextKey, context);
|
||||
Sentry.captureMessage(message, severity);
|
||||
});
|
||||
|
|
|
@ -16,6 +16,6 @@ initMonitoring({
|
|||
config: {
|
||||
...config,
|
||||
release: version,
|
||||
integrations: [new Sentry.Integrations.LinkedErrors({ key: 'jse_cause' })],
|
||||
integrations: [Sentry.linkedErrorsIntegration({ key: 'jse_cause' })],
|
||||
},
|
||||
});
|
||||
|
|
|
@ -106,18 +106,11 @@ exports.create = async function createServer() {
|
|||
// looks like there might be some other solutions that are more complex, but would work
|
||||
// with hapi and distributed tracing.
|
||||
//
|
||||
const transaction = Sentry.startTransaction(
|
||||
{
|
||||
op: 'profile-server',
|
||||
name: `${request.method.toUpperCase()} ${request.path}`,
|
||||
},
|
||||
{
|
||||
request: Sentry.Handlers.extractRequestData(request.raw.req),
|
||||
}
|
||||
);
|
||||
|
||||
Sentry.configureScope((scope) => {
|
||||
scope.setSpan(transaction);
|
||||
const transaction = Sentry.startInactiveSpan({
|
||||
op: 'profile-server',
|
||||
name: `${request.method.toUpperCase()} ${request.path}`,
|
||||
forceTransaction: true,
|
||||
request: Sentry.extractRequestData(request.raw.req),
|
||||
});
|
||||
|
||||
request.app.sentry = {
|
||||
|
|
|
@ -140,9 +140,9 @@ export function reportRequestException(
|
|||
Sentry.withScope((scope: Sentry.Scope) => {
|
||||
scope.addEventProcessor((event: Sentry.Event) => {
|
||||
if (request) {
|
||||
const sentryEvent = Sentry.Handlers.parseRequest(event, request);
|
||||
sentryEvent.level = 'error';
|
||||
return sentryEvent;
|
||||
event.request = Sentry.extractRequestData(request);
|
||||
event.level = 'error';
|
||||
return event;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
|
|
|
@ -13,7 +13,6 @@ import {
|
|||
NestInterceptor,
|
||||
} from '@nestjs/common';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { Transaction } from '@sentry/types';
|
||||
|
||||
import {
|
||||
isApolloError,
|
||||
|
@ -27,13 +26,14 @@ export class SentryInterceptor implements NestInterceptor {
|
|||
// If there is http context request start a transaction for it. Note that this will not
|
||||
// pick up graphql queries
|
||||
const req = context.switchToHttp().getRequest();
|
||||
let transaction: Transaction;
|
||||
let transaction: Sentry.Span;
|
||||
if (req) {
|
||||
transaction = Sentry.startTransaction({
|
||||
transaction = Sentry.startInactiveSpan({
|
||||
op: 'nestjs.http',
|
||||
name: `${context.switchToHttp().getRequest().method} ${
|
||||
context.switchToHttp().getRequest().path
|
||||
}`,
|
||||
forceTransaction: true,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -60,7 +60,7 @@ export class SentryInterceptor implements NestInterceptor {
|
|||
},
|
||||
}),
|
||||
finalize(() => {
|
||||
transaction?.finish();
|
||||
transaction?.end();
|
||||
})
|
||||
);
|
||||
}
|
||||
|
|
|
@ -13,7 +13,6 @@
|
|||
*/
|
||||
|
||||
import { Request } from 'express';
|
||||
import { GraphQLError } from 'graphql';
|
||||
|
||||
import {
|
||||
ApolloServerPlugin,
|
||||
|
@ -23,7 +22,6 @@ import {
|
|||
} from '@apollo/server';
|
||||
import { Plugin } from '@nestjs/apollo';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { Transaction } from '@sentry/types';
|
||||
|
||||
import {
|
||||
ExtraContext,
|
||||
|
@ -35,14 +33,15 @@ import { Inject } from '@nestjs/common';
|
|||
import { MozLoggerService } from '../logger/logger.service';
|
||||
|
||||
interface Context extends BaseContext {
|
||||
transaction: Transaction;
|
||||
transaction: Sentry.Span;
|
||||
request: Request;
|
||||
}
|
||||
|
||||
export async function createContext(ctx: any): Promise<Context> {
|
||||
const transaction = Sentry.startTransaction({
|
||||
const transaction = Sentry.startInactiveSpan({
|
||||
op: 'gql',
|
||||
name: 'GraphQLTransaction',
|
||||
forceTransaction: true,
|
||||
});
|
||||
return { request: ctx.req, transaction };
|
||||
}
|
||||
|
@ -59,16 +58,16 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
|
|||
|
||||
if (request.operationName) {
|
||||
try {
|
||||
contextValue.transaction.setName(request.operationName!);
|
||||
contextValue.transaction.updateName(request.operationName!);
|
||||
} catch (err) {
|
||||
log.error('sentry-plugin', err);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
async willSendResponse({ contextValue }) {
|
||||
async willSendResponse({ contextValue: Context }) {
|
||||
try {
|
||||
contextValue.transaction.finish();
|
||||
contextValue.transaction.end();
|
||||
} catch (err) {
|
||||
log.error('sentry-plugin', err);
|
||||
}
|
||||
|
@ -77,18 +76,19 @@ export class SentryPlugin implements ApolloServerPlugin<Context> {
|
|||
async executionDidStart() {
|
||||
return {
|
||||
willResolveField({ contextValue, info }) {
|
||||
let span: any;
|
||||
let span: Sentry.Span;
|
||||
try {
|
||||
span = contextValue.transaction.startChild({
|
||||
span = Sentry.startInactiveSpan({
|
||||
op: 'resolver',
|
||||
description: `${info.parentType.name}.${info.fieldName}`,
|
||||
name: `${info.parentType.name}.${info.fieldName}`,
|
||||
scope: contextValue.transaction,
|
||||
});
|
||||
} catch (err) {
|
||||
log.error('sentry-plugin', err);
|
||||
}
|
||||
|
||||
return () => {
|
||||
span?.finish();
|
||||
span?.end();
|
||||
};
|
||||
},
|
||||
};
|
||||
|
|
|
@ -49,7 +49,11 @@ export const _Sentry = {
|
|||
* Modified error object data
|
||||
* @private
|
||||
*/
|
||||
function beforeSend(opts: SentryConfigOpts, event: Sentry.Event, hint?: any) {
|
||||
function beforeSend(
|
||||
opts: SentryConfigOpts,
|
||||
event: Sentry.ErrorEvent,
|
||||
hint?: Sentry.EventHint
|
||||
) {
|
||||
if (sentryEnabled === false) {
|
||||
return null;
|
||||
}
|
||||
|
@ -166,12 +170,7 @@ function configure(config: SentryConfigOpts, log?: ILogger) {
|
|||
try {
|
||||
Sentry.init({
|
||||
...opts,
|
||||
integrations: [
|
||||
Sentry.browserTracingIntegration({
|
||||
enableInp: true,
|
||||
}),
|
||||
],
|
||||
beforeSend: function (event: Sentry.Event, hint?: any) {
|
||||
beforeSend: function (event: Sentry.ErrorEvent, hint?: Sentry.EventHint) {
|
||||
return beforeSend(opts, event, hint);
|
||||
},
|
||||
});
|
||||
|
|
|
@ -46,7 +46,6 @@ export function initSentry(config: InitSentryOpts, log: ILogger) {
|
|||
try {
|
||||
Sentry.init({
|
||||
// Defaults Options
|
||||
instrumenter: 'otel',
|
||||
normalizeDepth: 6,
|
||||
maxValueLength: 500,
|
||||
|
||||
|
|
|
@ -3,12 +3,7 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
import { assert } from 'chai';
|
||||
import {
|
||||
BrowserClient,
|
||||
makeFetchTransport,
|
||||
defaultStackParser,
|
||||
makeXHRTransport,
|
||||
} from '@sentry/browser';
|
||||
import { BrowserClient } from '@sentry/browser';
|
||||
import moment from 'moment';
|
||||
import sinon from 'sinon';
|
||||
|
||||
|
|
|
@ -56,7 +56,7 @@ describe('sentry/browser', () => {
|
|||
it('works without request url', () => {
|
||||
const data = {
|
||||
key: 'value',
|
||||
} as Sentry.Event;
|
||||
} as unknown as Sentry.ErrorEvent;
|
||||
|
||||
const resultData = sentryMetrics.__beforeSend(config, data, {});
|
||||
|
||||
|
@ -71,7 +71,7 @@ describe('sentry/browser', () => {
|
|||
tags: {
|
||||
errno: '100',
|
||||
},
|
||||
} as Sentry.Event;
|
||||
} as unknown as Sentry.ErrorEvent;
|
||||
|
||||
const resultData = sentryMetrics.__beforeSend(config, data, {});
|
||||
|
||||
|
@ -92,7 +92,7 @@ describe('sentry/browser', () => {
|
|||
request: {
|
||||
url: url + badQuery,
|
||||
},
|
||||
};
|
||||
} as unknown as Sentry.ErrorEvent;
|
||||
|
||||
const goodData = {
|
||||
request: {
|
||||
|
@ -115,7 +115,7 @@ describe('sentry/browser', () => {
|
|||
Referer: url + badQuery,
|
||||
},
|
||||
},
|
||||
};
|
||||
} as unknown as Sentry.ErrorEvent;
|
||||
|
||||
const goodData = {
|
||||
request: {
|
||||
|
@ -161,7 +161,7 @@ describe('sentry/browser', () => {
|
|||
request: {
|
||||
url,
|
||||
},
|
||||
};
|
||||
} as unknown as Sentry.ErrorEvent;
|
||||
|
||||
const resultData = sentryMetrics.__beforeSend(config, data);
|
||||
|
||||
|
@ -227,7 +227,7 @@ describe('sentry/browser', () => {
|
|||
|
||||
it('will return null from before send when disabled', () => {
|
||||
sentryMetrics.disable();
|
||||
assert.isNull(sentryMetrics.__beforeSend({}, {}, {}));
|
||||
assert.isNull(sentryMetrics.__beforeSend({}, {} as any, {}));
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node';
|
||||
import { TracingOpts } from '../config';
|
||||
import {
|
||||
SentrySpanProcessor,
|
||||
SentryPropagator,
|
||||
} from '@sentry/opentelemetry-node';
|
||||
import { SentrySpanProcessor, SentryPropagator } from '@sentry/opentelemetry';
|
||||
import { TracingPiiFilter } from '../pii-filters';
|
||||
import { ILogger } from '../../log';
|
||||
|
||||
|
|
736
yarn.lock
736
yarn.lock
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
Загрузка…
Ссылка в новой задаче