@envelop/newrelic 3.0.1-alpha-304a55e.0 → 3.2.0-alpha-e295e8c.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +55 -24
- package/index.mjs +37 -23
- package/package.json +2 -2
package/index.js
CHANGED
|
@@ -2,13 +2,28 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
4
|
|
|
5
|
-
function
|
|
5
|
+
function _interopNamespace(e) {
|
|
6
|
+
if (e && e.__esModule) { return e; } else {
|
|
7
|
+
var n = {};
|
|
8
|
+
if (e) {
|
|
9
|
+
Object.keys(e).forEach(function (k) {
|
|
10
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
11
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
12
|
+
enumerable: true,
|
|
13
|
+
get: function () {
|
|
14
|
+
return e[k];
|
|
15
|
+
}
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
n['default'] = e;
|
|
20
|
+
return n;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
6
23
|
|
|
7
|
-
const newRelic = _interopDefault(require('newrelic'));
|
|
8
24
|
const core = require('@envelop/core');
|
|
9
25
|
const graphql = require('graphql');
|
|
10
26
|
|
|
11
|
-
const { shim: instrumentationApi } = newRelic;
|
|
12
27
|
var AttributeName;
|
|
13
28
|
(function (AttributeName) {
|
|
14
29
|
AttributeName["COMPONENT_NAME"] = "Envelop_NewRelic_Plugin";
|
|
@@ -44,14 +59,21 @@ const useNewRelic = (rawOptions) => {
|
|
|
44
59
|
};
|
|
45
60
|
options.isExecuteVariablesRegex = options.includeExecuteVariables instanceof RegExp;
|
|
46
61
|
options.isResolverArgsRegex = options.includeResolverArgs instanceof RegExp;
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`)
|
|
51
|
-
|
|
62
|
+
const instrumentationApi$ = new Promise(function (resolve) { resolve(_interopNamespace(require('newrelic'))); })
|
|
63
|
+
.then(m => m.default || m)
|
|
64
|
+
.then(({ shim }) => {
|
|
65
|
+
shim.agent.metrics.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`).incrementCallCount();
|
|
66
|
+
return shim;
|
|
67
|
+
});
|
|
68
|
+
const logger$ = instrumentationApi$.then(({ logger }) => {
|
|
69
|
+
const childLogger = logger.child({ component: AttributeName.COMPONENT_NAME });
|
|
70
|
+
childLogger.info(`${AttributeName.COMPONENT_NAME} registered`);
|
|
71
|
+
return childLogger;
|
|
72
|
+
});
|
|
52
73
|
return {
|
|
53
|
-
onExecute({ args }) {
|
|
74
|
+
async onExecute({ args }) {
|
|
54
75
|
var _a;
|
|
76
|
+
const instrumentationApi = await instrumentationApi$;
|
|
55
77
|
const transactionNameState = instrumentationApi.agent.tracer.getTransaction().nameState;
|
|
56
78
|
const spanContext = instrumentationApi.agent.tracer.getSpanContext();
|
|
57
79
|
const delimiter = transactionNameState.delimiter;
|
|
@@ -80,7 +102,8 @@ const useNewRelic = (rawOptions) => {
|
|
|
80
102
|
}
|
|
81
103
|
const operationSegment = instrumentationApi.getActiveSegment();
|
|
82
104
|
const onResolverCalled = options.trackResolvers
|
|
83
|
-
? ({ args: resolversArgs, info }) => {
|
|
105
|
+
? async ({ args: resolversArgs, info }) => {
|
|
106
|
+
const logger = await logger$;
|
|
84
107
|
const { returnType, path, parentType } = info;
|
|
85
108
|
const formattedPath = flattenPath(path, delimiter);
|
|
86
109
|
const currentSegment = instrumentationApi.getActiveSegment();
|
|
@@ -120,23 +143,31 @@ const useNewRelic = (rawOptions) => {
|
|
|
120
143
|
return {
|
|
121
144
|
onResolverCalled,
|
|
122
145
|
onExecuteDone({ result }) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
const agent = instrumentationApi.agent;
|
|
134
|
-
const transaction = instrumentationApi.tracer.getTransaction();
|
|
135
|
-
for (const error of result.errors) {
|
|
136
|
-
agent.errors.add(transaction, JSON.stringify(error));
|
|
146
|
+
const sendResult = (singularResult) => {
|
|
147
|
+
if (singularResult.data && options.includeRawResult) {
|
|
148
|
+
spanContext.addCustomAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(singularResult));
|
|
149
|
+
}
|
|
150
|
+
if (singularResult.errors && singularResult.errors.length > 0) {
|
|
151
|
+
const agent = instrumentationApi.agent;
|
|
152
|
+
const transaction = instrumentationApi.tracer.getTransaction();
|
|
153
|
+
for (const error of singularResult.errors) {
|
|
154
|
+
agent.errors.add(transaction, JSON.stringify(error));
|
|
155
|
+
}
|
|
137
156
|
}
|
|
157
|
+
};
|
|
158
|
+
if (core.isAsyncIterable(result)) {
|
|
159
|
+
return {
|
|
160
|
+
onNext: ({ result: singularResult }) => {
|
|
161
|
+
sendResult(singularResult);
|
|
162
|
+
},
|
|
163
|
+
onEnd: () => {
|
|
164
|
+
operationSegment.end();
|
|
165
|
+
},
|
|
166
|
+
};
|
|
138
167
|
}
|
|
168
|
+
sendResult(result);
|
|
139
169
|
operationSegment.end();
|
|
170
|
+
return {};
|
|
140
171
|
},
|
|
141
172
|
};
|
|
142
173
|
},
|
package/index.mjs
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import newRelic from 'newrelic';
|
|
2
1
|
import { EnvelopError, isAsyncIterable } from '@envelop/core';
|
|
3
2
|
import { Kind, print } from 'graphql';
|
|
4
3
|
|
|
5
|
-
const { shim: instrumentationApi } = newRelic;
|
|
6
4
|
var AttributeName;
|
|
7
5
|
(function (AttributeName) {
|
|
8
6
|
AttributeName["COMPONENT_NAME"] = "Envelop_NewRelic_Plugin";
|
|
@@ -38,14 +36,21 @@ const useNewRelic = (rawOptions) => {
|
|
|
38
36
|
};
|
|
39
37
|
options.isExecuteVariablesRegex = options.includeExecuteVariables instanceof RegExp;
|
|
40
38
|
options.isResolverArgsRegex = options.includeResolverArgs instanceof RegExp;
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`)
|
|
45
|
-
|
|
39
|
+
const instrumentationApi$ = import('newrelic')
|
|
40
|
+
.then(m => m.default || m)
|
|
41
|
+
.then(({ shim }) => {
|
|
42
|
+
shim.agent.metrics.getOrCreateMetric(`Supportability/ExternalModules/${AttributeName.COMPONENT_NAME}`).incrementCallCount();
|
|
43
|
+
return shim;
|
|
44
|
+
});
|
|
45
|
+
const logger$ = instrumentationApi$.then(({ logger }) => {
|
|
46
|
+
const childLogger = logger.child({ component: AttributeName.COMPONENT_NAME });
|
|
47
|
+
childLogger.info(`${AttributeName.COMPONENT_NAME} registered`);
|
|
48
|
+
return childLogger;
|
|
49
|
+
});
|
|
46
50
|
return {
|
|
47
|
-
onExecute({ args }) {
|
|
51
|
+
async onExecute({ args }) {
|
|
48
52
|
var _a;
|
|
53
|
+
const instrumentationApi = await instrumentationApi$;
|
|
49
54
|
const transactionNameState = instrumentationApi.agent.tracer.getTransaction().nameState;
|
|
50
55
|
const spanContext = instrumentationApi.agent.tracer.getSpanContext();
|
|
51
56
|
const delimiter = transactionNameState.delimiter;
|
|
@@ -74,7 +79,8 @@ const useNewRelic = (rawOptions) => {
|
|
|
74
79
|
}
|
|
75
80
|
const operationSegment = instrumentationApi.getActiveSegment();
|
|
76
81
|
const onResolverCalled = options.trackResolvers
|
|
77
|
-
? ({ args: resolversArgs, info }) => {
|
|
82
|
+
? async ({ args: resolversArgs, info }) => {
|
|
83
|
+
const logger = await logger$;
|
|
78
84
|
const { returnType, path, parentType } = info;
|
|
79
85
|
const formattedPath = flattenPath(path, delimiter);
|
|
80
86
|
const currentSegment = instrumentationApi.getActiveSegment();
|
|
@@ -114,23 +120,31 @@ const useNewRelic = (rawOptions) => {
|
|
|
114
120
|
return {
|
|
115
121
|
onResolverCalled,
|
|
116
122
|
onExecuteDone({ result }) {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
if (result.data && options.includeRawResult) {
|
|
124
|
-
spanContext.addCustomAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(result));
|
|
125
|
-
}
|
|
126
|
-
if (result.errors && result.errors.length > 0) {
|
|
127
|
-
const agent = instrumentationApi.agent;
|
|
128
|
-
const transaction = instrumentationApi.tracer.getTransaction();
|
|
129
|
-
for (const error of result.errors) {
|
|
130
|
-
agent.errors.add(transaction, JSON.stringify(error));
|
|
123
|
+
const sendResult = (singularResult) => {
|
|
124
|
+
if (singularResult.data && options.includeRawResult) {
|
|
125
|
+
spanContext.addCustomAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(singularResult));
|
|
131
126
|
}
|
|
127
|
+
if (singularResult.errors && singularResult.errors.length > 0) {
|
|
128
|
+
const agent = instrumentationApi.agent;
|
|
129
|
+
const transaction = instrumentationApi.tracer.getTransaction();
|
|
130
|
+
for (const error of singularResult.errors) {
|
|
131
|
+
agent.errors.add(transaction, JSON.stringify(error));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
};
|
|
135
|
+
if (isAsyncIterable(result)) {
|
|
136
|
+
return {
|
|
137
|
+
onNext: ({ result: singularResult }) => {
|
|
138
|
+
sendResult(singularResult);
|
|
139
|
+
},
|
|
140
|
+
onEnd: () => {
|
|
141
|
+
operationSegment.end();
|
|
142
|
+
},
|
|
143
|
+
};
|
|
132
144
|
}
|
|
145
|
+
sendResult(result);
|
|
133
146
|
operationSegment.end();
|
|
147
|
+
return {};
|
|
134
148
|
},
|
|
135
149
|
};
|
|
136
150
|
},
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/newrelic",
|
|
3
|
-
"version": "3.0
|
|
3
|
+
"version": "3.2.0-alpha-e295e8c.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.
|
|
6
|
+
"@envelop/core": "^2.1.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
8
8
|
"newrelic": "^7 || ^8.0.0"
|
|
9
9
|
},
|