Add gql operationName metadata in sentry (#19564)
This commit is contained in:
+18
-1
@@ -1,3 +1,4 @@
|
||||
import * as Sentry from '@sentry/node';
|
||||
import { type Request } from 'express';
|
||||
import { DocumentNode, parse } from 'graphql';
|
||||
import { type Plugin } from 'graphql-yoga';
|
||||
@@ -36,8 +37,13 @@ export function useDirectExecution(
|
||||
return;
|
||||
}
|
||||
|
||||
const operationDefinition = findOperationDefinition(
|
||||
document,
|
||||
operationName,
|
||||
);
|
||||
|
||||
if (
|
||||
!findOperationDefinition(document, operationName) ||
|
||||
!operationDefinition ||
|
||||
isSubscriptionOperation(document, operationName)
|
||||
) {
|
||||
return;
|
||||
@@ -67,6 +73,17 @@ export function useDirectExecution(
|
||||
return;
|
||||
}
|
||||
|
||||
if (Sentry.isInitialized()) {
|
||||
const transactionName =
|
||||
operationName || operationDefinition.name?.value || '';
|
||||
|
||||
Sentry.setTags({
|
||||
operationName: transactionName,
|
||||
operation: operationDefinition.operation,
|
||||
});
|
||||
Sentry.getCurrentScope().setTransactionName(transactionName);
|
||||
}
|
||||
|
||||
const result = await config.directExecutionService.execute(
|
||||
req,
|
||||
document,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { type YogaDriverConfig } from '@graphql-yoga/nestjs';
|
||||
import * as Sentry from '@sentry/node';
|
||||
import GraphQLJSON from 'graphql-type-json';
|
||||
|
||||
import { NodeEnvironment } from 'src/engine/core-modules/twenty-config/interfaces/node-environment.interface';
|
||||
@@ -8,6 +9,7 @@ import { MetadataGraphQLApiModule } from 'src/engine/api/graphql/metadata-graphq
|
||||
import { type CacheStorageService } from 'src/engine/core-modules/cache-storage/services/cache-storage.service';
|
||||
import { ClientConfig } from 'src/engine/core-modules/client-config/client-config.entity';
|
||||
import { type ExceptionHandlerService } from 'src/engine/core-modules/exception-handler/exception-handler.service';
|
||||
import { useSentryTracing } from 'src/engine/core-modules/exception-handler/hooks/use-sentry-tracing';
|
||||
import { type FeatureFlagService } from 'src/engine/core-modules/feature-flag/services/feature-flag.service';
|
||||
import { useDisableIntrospectionAndSuggestionsForUnauthenticatedUsers } from 'src/engine/core-modules/graphql/hooks/use-disable-introspection-and-suggestions-for-unauthenticated-users.hook';
|
||||
import { useGraphQLErrorHandlerHook } from 'src/engine/core-modules/graphql/hooks/use-graphql-error-handler.hook';
|
||||
@@ -39,6 +41,7 @@ export const metadataModuleFactory = async (
|
||||
},
|
||||
resolvers: { JSON: GraphQLJSON },
|
||||
plugins: [
|
||||
...(Sentry.isInitialized() ? [useSentryTracing()] : []),
|
||||
useGraphQLErrorHandlerHook({
|
||||
metricsService: metricsService,
|
||||
exceptionHandlerService,
|
||||
|
||||
Reference in New Issue
Block a user