@envelop/statsd 2.4.0-alpha-c0cc559.0 → 2.4.0-alpha-e9434aa.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 → cjs/index.js} +12 -16
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +13 -12
- package/package.json +34 -12
- package/{index.d.ts → typings/index.d.ts} +0 -0
- package/README.md +0 -46
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const metricNames = {
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStatsD = exports.metricNames = void 0;
|
|
4
|
+
const core_1 = require("@envelop/core");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
exports.metricNames = {
|
|
9
7
|
operationCount: 'operations.count',
|
|
10
8
|
errorCount: 'operations.error_count',
|
|
11
9
|
latency: 'operations.latency',
|
|
@@ -13,7 +11,7 @@ const metricNames = {
|
|
|
13
11
|
const statsDPluginTagsSymbol = Symbol('statsDPluginTagsSymbol');
|
|
14
12
|
const statsDPluginExecutionStartTimeSymbol = Symbol('statsDPluginExecutionStartTimeSymbol');
|
|
15
13
|
function getOperation(document) {
|
|
16
|
-
return document.definitions.find(def => def.kind ===
|
|
14
|
+
return document.definitions.find(def => def.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
17
15
|
}
|
|
18
16
|
function isParseFailure(parseResult) {
|
|
19
17
|
return parseResult === null || parseResult instanceof Error;
|
|
@@ -27,10 +25,10 @@ const useStatsD = (options) => {
|
|
|
27
25
|
return `${prefix}.${name}`;
|
|
28
26
|
}
|
|
29
27
|
function increaseErrorCount(tags) {
|
|
30
|
-
client.increment(createMetricName(metricNames.errorCount), tags);
|
|
28
|
+
client.increment(createMetricName(exports.metricNames.errorCount), tags);
|
|
31
29
|
}
|
|
32
30
|
function increaseOperationCount(tags) {
|
|
33
|
-
client.increment(createMetricName(metricNames.operationCount), tags);
|
|
31
|
+
client.increment(createMetricName(exports.metricNames.operationCount), tags);
|
|
34
32
|
}
|
|
35
33
|
return {
|
|
36
34
|
onEnveloped({ extendContext }) {
|
|
@@ -39,7 +37,7 @@ const useStatsD = (options) => {
|
|
|
39
37
|
});
|
|
40
38
|
},
|
|
41
39
|
onParse({ extendContext, params }) {
|
|
42
|
-
if (skipIntrospection &&
|
|
40
|
+
if (skipIntrospection && (0, core_1.isIntrospectionOperationString)(params.source)) {
|
|
43
41
|
return;
|
|
44
42
|
}
|
|
45
43
|
return function onParseDone(payload) {
|
|
@@ -78,7 +76,7 @@ const useStatsD = (options) => {
|
|
|
78
76
|
return {
|
|
79
77
|
onExecuteDone({ result }) {
|
|
80
78
|
const latency = Date.now() - args.contextValue[statsDPluginExecutionStartTimeSymbol];
|
|
81
|
-
if (
|
|
79
|
+
if ((0, core_1.isAsyncIterable)(result)) {
|
|
82
80
|
// eslint-disable-next-line no-console
|
|
83
81
|
console.warn(`Plugin "statsd" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
84
82
|
return;
|
|
@@ -88,13 +86,11 @@ const useStatsD = (options) => {
|
|
|
88
86
|
increaseErrorCount(tags);
|
|
89
87
|
}
|
|
90
88
|
else {
|
|
91
|
-
client.histogram(createMetricName(metricNames.latency), latency, tags);
|
|
89
|
+
client.histogram(createMetricName(exports.metricNames.latency), latency, tags);
|
|
92
90
|
}
|
|
93
91
|
},
|
|
94
92
|
};
|
|
95
93
|
},
|
|
96
94
|
};
|
|
97
95
|
};
|
|
98
|
-
|
|
99
|
-
exports.metricNames = metricNames;
|
|
100
96
|
exports.useStatsD = useStatsD;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useStatsD = exports.metricNames = void 0;
|
|
4
|
+
const core_1 = require("@envelop/core");
|
|
5
|
+
const graphql_1 = require("graphql");
|
|
6
|
+
exports.metricNames = {
|
|
5
7
|
operationCount: 'operations.count',
|
|
6
8
|
errorCount: 'operations.error_count',
|
|
7
9
|
latency: 'operations.latency',
|
|
@@ -9,7 +11,7 @@ const metricNames = {
|
|
|
9
11
|
const statsDPluginTagsSymbol = Symbol('statsDPluginTagsSymbol');
|
|
10
12
|
const statsDPluginExecutionStartTimeSymbol = Symbol('statsDPluginExecutionStartTimeSymbol');
|
|
11
13
|
function getOperation(document) {
|
|
12
|
-
return document.definitions.find(def => def.kind === Kind.OPERATION_DEFINITION);
|
|
14
|
+
return document.definitions.find(def => def.kind === graphql_1.Kind.OPERATION_DEFINITION);
|
|
13
15
|
}
|
|
14
16
|
function isParseFailure(parseResult) {
|
|
15
17
|
return parseResult === null || parseResult instanceof Error;
|
|
@@ -23,10 +25,10 @@ const useStatsD = (options) => {
|
|
|
23
25
|
return `${prefix}.${name}`;
|
|
24
26
|
}
|
|
25
27
|
function increaseErrorCount(tags) {
|
|
26
|
-
client.increment(createMetricName(metricNames.errorCount), tags);
|
|
28
|
+
client.increment(createMetricName(exports.metricNames.errorCount), tags);
|
|
27
29
|
}
|
|
28
30
|
function increaseOperationCount(tags) {
|
|
29
|
-
client.increment(createMetricName(metricNames.operationCount), tags);
|
|
31
|
+
client.increment(createMetricName(exports.metricNames.operationCount), tags);
|
|
30
32
|
}
|
|
31
33
|
return {
|
|
32
34
|
onEnveloped({ extendContext }) {
|
|
@@ -35,7 +37,7 @@ const useStatsD = (options) => {
|
|
|
35
37
|
});
|
|
36
38
|
},
|
|
37
39
|
onParse({ extendContext, params }) {
|
|
38
|
-
if (skipIntrospection && isIntrospectionOperationString(params.source)) {
|
|
40
|
+
if (skipIntrospection && (0, core_1.isIntrospectionOperationString)(params.source)) {
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
43
|
return function onParseDone(payload) {
|
|
@@ -74,7 +76,7 @@ const useStatsD = (options) => {
|
|
|
74
76
|
return {
|
|
75
77
|
onExecuteDone({ result }) {
|
|
76
78
|
const latency = Date.now() - args.contextValue[statsDPluginExecutionStartTimeSymbol];
|
|
77
|
-
if (isAsyncIterable(result)) {
|
|
79
|
+
if ((0, core_1.isAsyncIterable)(result)) {
|
|
78
80
|
// eslint-disable-next-line no-console
|
|
79
81
|
console.warn(`Plugin "statsd" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
80
82
|
return;
|
|
@@ -84,12 +86,11 @@ const useStatsD = (options) => {
|
|
|
84
86
|
increaseErrorCount(tags);
|
|
85
87
|
}
|
|
86
88
|
else {
|
|
87
|
-
client.histogram(createMetricName(metricNames.latency), latency, tags);
|
|
89
|
+
client.histogram(createMetricName(exports.metricNames.latency), latency, tags);
|
|
88
90
|
}
|
|
89
91
|
},
|
|
90
92
|
};
|
|
91
93
|
},
|
|
92
94
|
};
|
|
93
95
|
};
|
|
94
|
-
|
|
95
|
-
export { metricNames, useStatsD };
|
|
96
|
+
exports.useStatsD = useStatsD;
|
package/package.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/statsd",
|
|
3
|
-
"version": "2.4.0-alpha-
|
|
3
|
+
"version": "2.4.0-alpha-e9434aa.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "2.4.0-alpha-
|
|
6
|
+
"@envelop/core": "2.4.0-alpha-e9434aa.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
|
},
|
|
10
|
+
"dependencies": {},
|
|
10
11
|
"repository": {
|
|
11
12
|
"type": "git",
|
|
12
|
-
"url": "https://github.com/
|
|
13
|
+
"url": "https://github.com/n1ru4l/envelop.git",
|
|
13
14
|
"directory": "packages/plugins/statsd"
|
|
14
15
|
},
|
|
15
16
|
"keywords": [
|
|
@@ -21,21 +22,42 @@
|
|
|
21
22
|
],
|
|
22
23
|
"author": "Kamil Kisiela <kamil.kisiela@gmail.com>",
|
|
23
24
|
"license": "MIT",
|
|
24
|
-
"main": "index.js",
|
|
25
|
-
"module": "index.
|
|
26
|
-
"typings": "index.d.ts",
|
|
25
|
+
"main": "cjs/index.js",
|
|
26
|
+
"module": "esm/index.js",
|
|
27
|
+
"typings": "typings/index.d.ts",
|
|
27
28
|
"typescript": {
|
|
28
|
-
"definition": "index.d.ts"
|
|
29
|
+
"definition": "typings/index.d.ts"
|
|
29
30
|
},
|
|
31
|
+
"type": "module",
|
|
30
32
|
"exports": {
|
|
31
33
|
".": {
|
|
32
|
-
"require":
|
|
33
|
-
|
|
34
|
+
"require": {
|
|
35
|
+
"types": "./typings/index.d.ts",
|
|
36
|
+
"default": "./cjs/index.js"
|
|
37
|
+
},
|
|
38
|
+
"import": {
|
|
39
|
+
"types": "./typings/index.d.ts",
|
|
40
|
+
"default": "./esm/index.js"
|
|
41
|
+
},
|
|
42
|
+
"default": {
|
|
43
|
+
"types": "./typings/index.d.ts",
|
|
44
|
+
"default": "./esm/index.js"
|
|
45
|
+
}
|
|
34
46
|
},
|
|
35
47
|
"./*": {
|
|
36
|
-
"require":
|
|
37
|
-
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./typings/*.d.ts",
|
|
50
|
+
"default": "./cjs/*.js"
|
|
51
|
+
},
|
|
52
|
+
"import": {
|
|
53
|
+
"types": "./typings/*.d.ts",
|
|
54
|
+
"default": "./esm/*.js"
|
|
55
|
+
},
|
|
56
|
+
"default": {
|
|
57
|
+
"types": "./typings/*.d.ts",
|
|
58
|
+
"default": "./esm/*.js"
|
|
59
|
+
}
|
|
38
60
|
},
|
|
39
61
|
"./package.json": "./package.json"
|
|
40
62
|
}
|
|
41
|
-
}
|
|
63
|
+
}
|
|
File without changes
|
package/README.md
DELETED
|
@@ -1,46 +0,0 @@
|
|
|
1
|
-
## `@envelop/statsd`
|
|
2
|
-
|
|
3
|
-
This plugin tracks the complete execution flow, and reports metrics using StatsD (based on `hot-shots`).
|
|
4
|
-
|
|
5
|
-
Compatible with:
|
|
6
|
-
|
|
7
|
-
- Datadog's DogStatsD server
|
|
8
|
-
- InfluxDB's Telegraf StatsD server
|
|
9
|
-
- Etsy's StatsD serve
|
|
10
|
-
|
|
11
|
-
Available metrics:
|
|
12
|
-
|
|
13
|
-
- `graphql.operations.count` - the number of performed operations (including failures)
|
|
14
|
-
- `graphql.operations.error_count` - the number of failed operations
|
|
15
|
-
- `graphql.operations.latency` - a histogram of response times (in milliseconds)
|
|
16
|
-
|
|
17
|
-
> You can also customize the `graphql` prefix and add custom tags to the metrics.
|
|
18
|
-
|
|
19
|
-
## Getting Started
|
|
20
|
-
|
|
21
|
-
```
|
|
22
|
-
yarn add hot-shots @envelop/stats
|
|
23
|
-
```
|
|
24
|
-
|
|
25
|
-
## Usage Example
|
|
26
|
-
|
|
27
|
-
```ts
|
|
28
|
-
import { envelop } from '@envelop/core';
|
|
29
|
-
import { useStatsD } from '@envelop/statsd';
|
|
30
|
-
|
|
31
|
-
const client = new StatsD({
|
|
32
|
-
port: 8020,
|
|
33
|
-
globalTags: { env: process.env.NODE_ENV },
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
const getEnveloped = envelop({
|
|
37
|
-
plugins: [
|
|
38
|
-
// ... other plugins ...
|
|
39
|
-
useStatsD({
|
|
40
|
-
client,
|
|
41
|
-
prefix: 'gql', // results in `gql.operations.count` instead of `graphql.operations.count`,
|
|
42
|
-
skipIntrospection: true, // if you wish to disable introspection logging
|
|
43
|
-
}),
|
|
44
|
-
],
|
|
45
|
-
});
|
|
46
|
-
```
|