@envelop/statsd 3.0.0-alpha-d0d0776.0 → 3.0.0-alpha-ccec0fc.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/README.md CHANGED
@@ -25,13 +25,14 @@ yarn add hot-shots @envelop/stats
25
25
  ## Usage Example
26
26
 
27
27
  ```ts
28
- import { envelop } from '@envelop/core';
29
- import { useStatsD } from '@envelop/statsd';
28
+ import { envelop } from '@envelop/core'
29
+ import { useStatsD } from '@envelop/statsd'
30
+ import StatsD from 'hot-shots'
30
31
 
31
32
  const client = new StatsD({
32
33
  port: 8020,
33
- globalTags: { env: process.env.NODE_ENV },
34
- });
34
+ globalTags: { env: process.env.NODE_ENV }
35
+ })
35
36
 
36
37
  const getEnveloped = envelop({
37
38
  plugins: [
@@ -39,8 +40,8 @@ const getEnveloped = envelop({
39
40
  useStatsD({
40
41
  client,
41
42
  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
- });
43
+ skipIntrospection: true // if you wish to disable introspection logging
44
+ })
45
+ ]
46
+ })
46
47
  ```
@@ -1,11 +1,9 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- const core = require('@envelop/core');
6
- const graphql = require('graphql');
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-tools/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 === graphql.Kind.OPERATION_DEFINITION);
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,10 +37,11 @@ const useStatsD = (options) => {
39
37
  });
40
38
  },
41
39
  onParse({ extendContext, params }) {
42
- if (skipIntrospection && core.isIntrospectionOperationString(params.source)) {
40
+ if (skipIntrospection && (0, core_1.isIntrospectionOperationString)(params.source)) {
43
41
  return;
44
42
  }
45
43
  return function onParseDone(payload) {
44
+ var _a;
46
45
  if (isParseFailure(payload.result)) {
47
46
  increaseErrorCount();
48
47
  increaseOperationCount();
@@ -51,7 +50,7 @@ const useStatsD = (options) => {
51
50
  const operation = getOperation(payload.result);
52
51
  extendContext({
53
52
  [statsDPluginTagsSymbol]: {
54
- operation: operation?.name?.value || 'anonymous',
53
+ operation: ((_a = operation === null || operation === void 0 ? void 0 : operation.name) === null || _a === void 0 ? void 0 : _a.value) || 'anonymous',
55
54
  },
56
55
  });
57
56
  }
@@ -77,7 +76,7 @@ const useStatsD = (options) => {
77
76
  return {
78
77
  onExecuteDone({ result }) {
79
78
  const latency = Date.now() - args.contextValue[statsDPluginExecutionStartTimeSymbol];
80
- if (core.isAsyncIterable(result)) {
79
+ if ((0, core_1.isAsyncIterable)(result)) {
81
80
  // eslint-disable-next-line no-console
82
81
  console.warn(`Plugin "statsd" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
83
82
  return;
@@ -87,13 +86,11 @@ const useStatsD = (options) => {
87
86
  increaseErrorCount(tags);
88
87
  }
89
88
  else {
90
- client.histogram(createMetricName(metricNames.latency), latency, tags);
89
+ client.histogram(createMetricName(exports.metricNames.latency), latency, tags);
91
90
  }
92
91
  },
93
92
  };
94
93
  },
95
94
  };
96
95
  };
97
-
98
- exports.metricNames = metricNames;
99
96
  exports.useStatsD = useStatsD;
@@ -0,0 +1 @@
1
+ {"type":"commonjs"}
@@ -1,7 +1,6 @@
1
1
  import { isIntrospectionOperationString, isAsyncIterable } from '@envelop/core';
2
- import { Kind } from 'graphql';
3
-
4
- const metricNames = {
2
+ import { Kind } from '@graphql-tools/graphql';
3
+ export const metricNames = {
5
4
  operationCount: 'operations.count',
6
5
  errorCount: 'operations.error_count',
7
6
  latency: 'operations.latency',
@@ -17,7 +16,7 @@ function isParseFailure(parseResult) {
17
16
  function getTags(context) {
18
17
  return context[statsDPluginTagsSymbol];
19
18
  }
20
- const useStatsD = (options) => {
19
+ export const useStatsD = (options) => {
21
20
  const { client, prefix = 'graphql', skipIntrospection = false } = options;
22
21
  function createMetricName(name) {
23
22
  return `${prefix}.${name}`;
@@ -39,6 +38,7 @@ const useStatsD = (options) => {
39
38
  return;
40
39
  }
41
40
  return function onParseDone(payload) {
41
+ var _a;
42
42
  if (isParseFailure(payload.result)) {
43
43
  increaseErrorCount();
44
44
  increaseOperationCount();
@@ -47,7 +47,7 @@ const useStatsD = (options) => {
47
47
  const operation = getOperation(payload.result);
48
48
  extendContext({
49
49
  [statsDPluginTagsSymbol]: {
50
- operation: operation?.name?.value || 'anonymous',
50
+ operation: ((_a = operation === null || operation === void 0 ? void 0 : operation.name) === null || _a === void 0 ? void 0 : _a.value) || 'anonymous',
51
51
  },
52
52
  });
53
53
  }
@@ -90,5 +90,3 @@ const useStatsD = (options) => {
90
90
  },
91
91
  };
92
92
  };
93
-
94
- export { metricNames, useStatsD };
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@envelop/statsd",
3
- "version": "3.0.0-alpha-d0d0776.0",
3
+ "version": "3.0.0-alpha-ccec0fc.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
- "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0",
6
+ "@envelop/core": "3.0.0-alpha-ccec0fc.0",
7
+ "@graphql-tools/graphql": "0.1.0-alpha-e7752ba5.0",
8
8
  "hot-shots": "^8.0.0 || ^9.0.0"
9
9
  },
10
+ "dependencies": {},
10
11
  "repository": {
11
12
  "type": "git",
12
13
  "url": "https://github.com/n1ru4l/envelop.git",
@@ -21,33 +22,42 @@
21
22
  ],
22
23
  "author": "Kamil Kisiela <kamil.kisiela@gmail.com>",
23
24
  "license": "MIT",
24
- "main": "index.js",
25
- "module": "index.mjs",
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
34
  "require": {
33
- "default": "./index.js",
34
- "types": "./index.d.ts"
35
+ "types": "./typings/index.d.ts",
36
+ "default": "./cjs/index.js"
35
37
  },
36
38
  "import": {
37
- "default": "./index.mjs",
38
- "types": "./index.d.ts"
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"
39
45
  }
40
46
  },
41
47
  "./*": {
42
48
  "require": {
43
- "default": "./*.js",
44
- "types": "./*.d.ts"
49
+ "types": "./typings/*.d.ts",
50
+ "default": "./cjs/*.js"
45
51
  },
46
52
  "import": {
47
- "default": "./*.mjs",
48
- "types": "./*.d.ts"
53
+ "types": "./typings/*.d.ts",
54
+ "default": "./esm/*.js"
55
+ },
56
+ "default": {
57
+ "types": "./typings/*.d.ts",
58
+ "default": "./esm/*.js"
49
59
  }
50
60
  },
51
61
  "./package.json": "./package.json"
52
62
  }
53
- }
63
+ }
File without changes