Add sentry tracing (#4279)
* Add sentry tracign * Improve Sentry loggin
This commit is contained in:
@ -16,18 +16,14 @@ export class ExceptionHandlerSentryDriver
|
||||
Sentry.init({
|
||||
dsn: options.dsn,
|
||||
integrations: [
|
||||
// enable HTTP calls tracing
|
||||
new Sentry.Integrations.Http({ tracing: true }),
|
||||
// enable Express.js middleware tracing
|
||||
new Sentry.Integrations.Express({ app: options.serverInstance }),
|
||||
new Sentry.Integrations.GraphQL(),
|
||||
new Sentry.Integrations.Postgres({
|
||||
usePgNative: true,
|
||||
}),
|
||||
new Sentry.Integrations.Postgres(),
|
||||
new ProfilingIntegration(),
|
||||
],
|
||||
tracesSampleRate: 1.0,
|
||||
profilesSampleRate: 1.0,
|
||||
tracesSampleRate: 1,
|
||||
profilesSampleRate: 0.05,
|
||||
environment: options.debug ? 'development' : 'production',
|
||||
debug: options.debug,
|
||||
});
|
||||
@ -52,9 +48,11 @@ export class ExceptionHandlerSentryDriver
|
||||
if (options?.user) {
|
||||
scope.setUser({
|
||||
id: options.user.id,
|
||||
ip_address: options.user.ipAddress,
|
||||
email: options.user.email,
|
||||
username: options.user.username,
|
||||
firstName: options.user.firstName,
|
||||
lastName: options.user.lastName,
|
||||
workspaceId: options.user.workspaceId,
|
||||
workspaceDisplayName: options.user.workspaceDisplayName,
|
||||
});
|
||||
}
|
||||
|
||||
@ -98,9 +96,11 @@ export class ExceptionHandlerSentryDriver
|
||||
if (user) {
|
||||
scope.setUser({
|
||||
id: user.id,
|
||||
ip_address: user.ipAddress,
|
||||
email: user.email,
|
||||
username: user.username,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
workspaceId: user.workspaceId,
|
||||
workspaceDisplayName: user.workspaceDisplayName,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
export interface ExceptionHandlerUser {
|
||||
id?: string;
|
||||
ipAddress?: string;
|
||||
email?: string;
|
||||
username?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
workspaceId?: string;
|
||||
workspaceDisplayName?: string;
|
||||
}
|
||||
|
||||
@ -0,0 +1,57 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
import {
|
||||
handleStreamOrSingleExecutionResult,
|
||||
Plugin,
|
||||
getDocumentString,
|
||||
} from '@envelop/core';
|
||||
import { OperationDefinitionNode, Kind, print } from 'graphql';
|
||||
|
||||
import { GraphQLContext } from 'src/graphql-config/graphql-config.service';
|
||||
|
||||
export const useSentryTracing = <
|
||||
PluginContext extends GraphQLContext,
|
||||
>(): Plugin<PluginContext> => {
|
||||
return {
|
||||
onExecute({ args }) {
|
||||
const transactionName = args.operationName || 'Anonymous Operation';
|
||||
const rootOperation = args.document.definitions.find(
|
||||
(o) => o.kind === Kind.OPERATION_DEFINITION,
|
||||
) as OperationDefinitionNode;
|
||||
const operationType = rootOperation.operation;
|
||||
|
||||
const user = args.contextValue.user;
|
||||
const workspace = args.contextValue.workspace;
|
||||
const document = getDocumentString(args.document, print);
|
||||
|
||||
Sentry.setTags({
|
||||
operationName: transactionName,
|
||||
operation: operationType,
|
||||
});
|
||||
|
||||
const scope = Sentry.getCurrentScope();
|
||||
|
||||
scope.setTransactionName(transactionName);
|
||||
|
||||
if (user) {
|
||||
scope.setUser({
|
||||
id: user.id,
|
||||
email: user.email,
|
||||
firstName: user.firstName,
|
||||
lastName: user.lastName,
|
||||
workspaceId: workspace?.id,
|
||||
workspaceDisplayName: workspace?.displayName,
|
||||
});
|
||||
}
|
||||
|
||||
if (document) {
|
||||
scope.setExtra('document', document);
|
||||
}
|
||||
|
||||
return {
|
||||
onExecuteDone(payload) {
|
||||
return handleStreamOrSingleExecutionResult(payload, () => {});
|
||||
},
|
||||
};
|
||||
},
|
||||
};
|
||||
};
|
||||
Reference in New Issue
Block a user