@@ -2,11 +2,20 @@ import { NativeModules, Platform } from 'react-native';
2
2
import xhr from '../utils/XhrNetworkInterceptor' ;
3
3
import IBGEventEmitter from '../utils/IBGEventEmitter.js' ;
4
4
import InstabugConstants from '../utils/InstabugConstants' ;
5
- let { Instabug } = NativeModules ;
6
-
5
+ let { Instabug, IBGAPM } = NativeModules ;
7
6
8
7
var _networkDataObfuscationHandlerSet = false ;
9
8
var _requestFilterExpression = false ;
9
+ const appendOperationName = ( headers , operationName ) => {
10
+ try {
11
+ let newHeaders = JSON . parse ( JSON . stringify ( headers ) ) ;
12
+ newHeaders [ InstabugConstants . GRAPHQL_HEADER ] = operationName ;
13
+ return newHeaders ;
14
+ } catch ( e ) {
15
+ console . error ( e ) ;
16
+ return headers ;
17
+ }
18
+ } ;
10
19
11
20
/**
12
21
* NetworkLogger
@@ -32,6 +41,7 @@ export default {
32
41
try {
33
42
if ( Platform . OS === 'android' ) {
34
43
Instabug . networkLog ( JSON . stringify ( network ) ) ;
44
+ IBGAPM . networkLog ( JSON . stringify ( network ) ) ;
35
45
} else {
36
46
Instabug . networkLog ( network ) ;
37
47
}
@@ -57,13 +67,15 @@ export default {
57
67
}
58
68
_networkDataObfuscationHandlerSet = true ;
59
69
60
- IBGEventEmitter . addListener ( Instabug ,
70
+ IBGEventEmitter . addListener (
71
+ Instabug ,
61
72
InstabugConstants . NETWORK_DATA_OBFUSCATION_HANDLER_EVENT ,
62
73
async data => {
63
74
try {
64
75
const newData = await handler ( data ) ;
65
76
if ( Platform . OS === 'android' ) {
66
77
Instabug . networkLog ( JSON . stringify ( newData ) ) ;
78
+ IBGAPM . networkLog ( JSON . stringify ( newData ) ) ;
67
79
} else {
68
80
Instabug . networkLog ( newData ) ;
69
81
}
@@ -74,7 +86,6 @@ export default {
74
86
) ;
75
87
} ,
76
88
77
-
78
89
/**
79
90
* Omit requests from being logged based on either their request or response details
80
91
* @param {string } expression
@@ -91,5 +102,15 @@ export default {
91
102
xhr . setOnProgressCallback ( handler ) ;
92
103
} ,
93
104
105
+ apolloLinkRequestHandler ( operation , forward ) {
106
+ try {
107
+ operation . setContext ( ( { headers = { } } ) => ( {
108
+ headers : appendOperationName ( headers , operation . operationName ) ,
109
+ } ) ) ;
110
+ } catch ( e ) {
111
+ console . error ( e ) ;
112
+ }
94
113
114
+ return forward ( operation ) ;
115
+ } ,
95
116
} ;
0 commit comments