File tree Expand file tree Collapse file tree 4 files changed +350
-14
lines changed
packages/node-integration-tests
suites/tracing/apollo-graphql Expand file tree Collapse file tree 4 files changed +350
-14
lines changed Original file line number Diff line number Diff line change 2222 "@types/mongodb" : " ^3.6.20" ,
2323 "@types/mysql" : " ^2.15.21" ,
2424 "@types/pg" : " ^8.6.5" ,
25+ "apollo-server" : " ^3.6.7" ,
2526 "cors" : " ^2.8.5" ,
2627 "express" : " ^4.17.3" ,
28+ "graphql" : " ^16.3.0" ,
2729 "mongodb" : " ^3.7.3" ,
2830 "mongodb-memory-server-global" : " ^7.6.3" ,
2931 "mysql" : " ^2.18.1" ,
Original file line number Diff line number Diff line change 1+ import * as Sentry from '@sentry/node' ;
2+ import * as Tracing from '@sentry/tracing' ;
3+ import { ApolloServer , gql } from 'apollo-server' ;
4+
5+ Sentry . init ( {
6+ dsn :
'https://[email protected] /1337' , 7+ release : '1.0' ,
8+ tracesSampleRate : 1.0 ,
9+ integrations : [ new Tracing . Integrations . GraphQL ( ) , new Tracing . Integrations . Apollo ( ) ] ,
10+ } ) ;
11+
12+ const typeDefs = gql `
13+ type Query {
14+ hello: String
15+ }
16+ ` ;
17+
18+ const resolvers = {
19+ Query : {
20+ hello : ( ) => {
21+ return 'Hello world!' ;
22+ } ,
23+ } ,
24+ } ;
25+
26+ const server = new ApolloServer ( {
27+ typeDefs,
28+ resolvers,
29+ } ) ;
30+
31+ const transaction = Sentry . startTransaction ( { name : 'test_transaction' , op : 'transaction' } ) ;
32+
33+ Sentry . configureScope ( scope => {
34+ scope . setSpan ( transaction ) ;
35+ } ) ;
36+
37+ void ( async ( ) => {
38+ // Ref: https://www.apollographql.com/docs/apollo-server/testing/testing/#testing-using-executeoperation
39+ await server . executeOperation ( {
40+ query : '{hello}' ,
41+ } ) ;
42+
43+ transaction . finish ( ) ;
44+ } ) ( ) ;
Original file line number Diff line number Diff line change 1+ import { assertSentryTransaction , getEnvelopeRequest , runServer } from '../../../utils' ;
2+
3+ test ( 'should instrument GraphQL and Apollo Server.' , async ( ) => {
4+ const url = await runServer ( __dirname ) ;
5+ const envelope = await getEnvelopeRequest ( url ) ;
6+
7+ expect ( envelope ) . toHaveLength ( 3 ) ;
8+
9+ const transaction = envelope [ 2 ] ;
10+ const parentSpanId = ( transaction as any ) ?. contexts ?. trace ?. span_id ;
11+ const graphqlSpanId = ( transaction as any ) ?. spans ?. [ 0 ] . span_id ;
12+
13+ expect ( parentSpanId ) . toBeDefined ( ) ;
14+ expect ( graphqlSpanId ) . toBeDefined ( ) ;
15+
16+ assertSentryTransaction ( transaction , {
17+ transaction : 'test_transaction' ,
18+ spans : [
19+ {
20+ description : 'execute' ,
21+ op : 'db.graphql' ,
22+ parent_span_id : parentSpanId ,
23+ } ,
24+ {
25+ description : 'Query.hello' ,
26+ op : 'db.graphql.apollo' ,
27+ parent_span_id : graphqlSpanId ,
28+ } ,
29+ ] ,
30+ } ) ;
31+ } ) ;
You can’t perform that action at this time.
0 commit comments