@envelop/statsd 2.4.0-alpha-e9434aa.0 → 2.4.0-alpha-05dbec7.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/esm/index.js +10 -14
- package/package.json +2 -2
package/esm/index.js
CHANGED
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const core_1 = require("@envelop/core");
|
|
5
|
-
const graphql_1 = require("graphql");
|
|
6
|
-
exports.metricNames = {
|
|
1
|
+
import { isIntrospectionOperationString, isAsyncIterable } from '@envelop/core';
|
|
2
|
+
import { Kind } from 'graphql';
|
|
3
|
+
export const metricNames = {
|
|
7
4
|
operationCount: 'operations.count',
|
|
8
5
|
errorCount: 'operations.error_count',
|
|
9
6
|
latency: 'operations.latency',
|
|
@@ -11,7 +8,7 @@ exports.metricNames = {
|
|
|
11
8
|
const statsDPluginTagsSymbol = Symbol('statsDPluginTagsSymbol');
|
|
12
9
|
const statsDPluginExecutionStartTimeSymbol = Symbol('statsDPluginExecutionStartTimeSymbol');
|
|
13
10
|
function getOperation(document) {
|
|
14
|
-
return document.definitions.find(def => def.kind ===
|
|
11
|
+
return document.definitions.find(def => def.kind === Kind.OPERATION_DEFINITION);
|
|
15
12
|
}
|
|
16
13
|
function isParseFailure(parseResult) {
|
|
17
14
|
return parseResult === null || parseResult instanceof Error;
|
|
@@ -19,16 +16,16 @@ function isParseFailure(parseResult) {
|
|
|
19
16
|
function getTags(context) {
|
|
20
17
|
return context[statsDPluginTagsSymbol];
|
|
21
18
|
}
|
|
22
|
-
const useStatsD = (options) => {
|
|
19
|
+
export const useStatsD = (options) => {
|
|
23
20
|
const { client, prefix = 'graphql', skipIntrospection = false } = options;
|
|
24
21
|
function createMetricName(name) {
|
|
25
22
|
return `${prefix}.${name}`;
|
|
26
23
|
}
|
|
27
24
|
function increaseErrorCount(tags) {
|
|
28
|
-
client.increment(createMetricName(
|
|
25
|
+
client.increment(createMetricName(metricNames.errorCount), tags);
|
|
29
26
|
}
|
|
30
27
|
function increaseOperationCount(tags) {
|
|
31
|
-
client.increment(createMetricName(
|
|
28
|
+
client.increment(createMetricName(metricNames.operationCount), tags);
|
|
32
29
|
}
|
|
33
30
|
return {
|
|
34
31
|
onEnveloped({ extendContext }) {
|
|
@@ -37,7 +34,7 @@ const useStatsD = (options) => {
|
|
|
37
34
|
});
|
|
38
35
|
},
|
|
39
36
|
onParse({ extendContext, params }) {
|
|
40
|
-
if (skipIntrospection &&
|
|
37
|
+
if (skipIntrospection && isIntrospectionOperationString(params.source)) {
|
|
41
38
|
return;
|
|
42
39
|
}
|
|
43
40
|
return function onParseDone(payload) {
|
|
@@ -76,7 +73,7 @@ const useStatsD = (options) => {
|
|
|
76
73
|
return {
|
|
77
74
|
onExecuteDone({ result }) {
|
|
78
75
|
const latency = Date.now() - args.contextValue[statsDPluginExecutionStartTimeSymbol];
|
|
79
|
-
if (
|
|
76
|
+
if (isAsyncIterable(result)) {
|
|
80
77
|
// eslint-disable-next-line no-console
|
|
81
78
|
console.warn(`Plugin "statsd" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
82
79
|
return;
|
|
@@ -86,11 +83,10 @@ const useStatsD = (options) => {
|
|
|
86
83
|
increaseErrorCount(tags);
|
|
87
84
|
}
|
|
88
85
|
else {
|
|
89
|
-
client.histogram(createMetricName(
|
|
86
|
+
client.histogram(createMetricName(metricNames.latency), latency, tags);
|
|
90
87
|
}
|
|
91
88
|
},
|
|
92
89
|
};
|
|
93
90
|
},
|
|
94
91
|
};
|
|
95
92
|
};
|
|
96
|
-
exports.useStatsD = useStatsD;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/statsd",
|
|
3
|
-
"version": "2.4.0-alpha-
|
|
3
|
+
"version": "2.4.0-alpha-05dbec7.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-05dbec7.0",
|
|
7
7
|
"graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
|
|
8
8
|
"hot-shots": "^8.0.0 || ^9.0.0"
|
|
9
9
|
},
|