@envelop/opentelemetry 3.4.0-alpha-aca44e1.0 → 3.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.mjs → cjs/index.js} +19 -16
- package/cjs/package.json +1 -0
- package/{index.js → esm/index.js} +47 -25
- package/package.json +33 -12
- package/{index.d.ts → typings/index.d.ts} +1 -1
- package/README.md +0 -62
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.useOpenTelemetry = exports.AttributeName = void 0;
|
|
4
|
+
const tslib_1 = require("tslib");
|
|
5
|
+
const core_1 = require("@envelop/core");
|
|
6
|
+
const api_1 = require("@opentelemetry/api");
|
|
7
|
+
const opentelemetry = tslib_1.__importStar(require("@opentelemetry/api"));
|
|
8
|
+
const tracing_1 = require("@opentelemetry/tracing");
|
|
9
|
+
const graphql_1 = require("graphql");
|
|
6
10
|
var AttributeName;
|
|
7
11
|
(function (AttributeName) {
|
|
8
12
|
AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
|
|
@@ -15,21 +19,21 @@ var AttributeName;
|
|
|
15
19
|
AttributeName["EXECUTION_OPERATION_NAME"] = "graphql.execute.operationName";
|
|
16
20
|
AttributeName["EXECUTION_OPERATION_DOCUMENT"] = "graphql.execute.document";
|
|
17
21
|
AttributeName["EXECUTION_VARIABLES"] = "graphql.execute.variables";
|
|
18
|
-
})(AttributeName || (AttributeName = {}));
|
|
22
|
+
})(AttributeName = exports.AttributeName || (exports.AttributeName = {}));
|
|
19
23
|
const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
|
|
20
|
-
const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
24
|
+
const useOpenTelemetry = (options, tracingProvider, spanKind = api_1.SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
21
25
|
if (!tracingProvider) {
|
|
22
|
-
tracingProvider = new BasicTracerProvider();
|
|
23
|
-
tracingProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
|
|
26
|
+
tracingProvider = new tracing_1.BasicTracerProvider();
|
|
27
|
+
tracingProvider.addSpanProcessor(new tracing_1.SimpleSpanProcessor(new tracing_1.ConsoleSpanExporter()));
|
|
24
28
|
tracingProvider.register();
|
|
25
29
|
}
|
|
26
30
|
const tracer = tracingProvider.getTracer(serviceName);
|
|
27
31
|
return {
|
|
28
32
|
onResolverCalled: options.resolvers
|
|
29
|
-
? ({ info, context
|
|
30
|
-
if (context
|
|
33
|
+
? ({ info, context, args }) => {
|
|
34
|
+
if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
|
|
31
35
|
tracer.getActiveSpanProcessor();
|
|
32
|
-
const ctx = trace.setSpan(context.active(), context
|
|
36
|
+
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
|
|
33
37
|
const { fieldName, returnType, parentType } = info;
|
|
34
38
|
const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
|
|
35
39
|
attributes: {
|
|
@@ -61,13 +65,13 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
|
|
|
61
65
|
attributes: {
|
|
62
66
|
...spanAdditionalAttributes,
|
|
63
67
|
[AttributeName.EXECUTION_OPERATION_NAME]: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
|
|
64
|
-
[AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(args.document),
|
|
68
|
+
[AttributeName.EXECUTION_OPERATION_DOCUMENT]: (0, graphql_1.print)(args.document),
|
|
65
69
|
...(options.variables ? { [AttributeName.EXECUTION_VARIABLES]: JSON.stringify((_b = args.variableValues) !== null && _b !== void 0 ? _b : {}) } : {}),
|
|
66
70
|
},
|
|
67
71
|
});
|
|
68
72
|
const resultCbs = {
|
|
69
73
|
onExecuteDone({ result }) {
|
|
70
|
-
if (isAsyncIterable(result)) {
|
|
74
|
+
if ((0, core_1.isAsyncIterable)(result)) {
|
|
71
75
|
executionSpan.end();
|
|
72
76
|
// eslint-disable-next-line no-console
|
|
73
77
|
console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
@@ -94,5 +98,4 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
|
|
|
94
98
|
},
|
|
95
99
|
};
|
|
96
100
|
};
|
|
97
|
-
|
|
98
|
-
export { AttributeName, useOpenTelemetry };
|
|
101
|
+
exports.useOpenTelemetry = useOpenTelemetry;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,12 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.useOpenTelemetry = exports.AttributeName = void 0;
|
|
27
|
+
const core_1 = require("@envelop/core");
|
|
28
|
+
const api_1 = require("@opentelemetry/api");
|
|
29
|
+
const opentelemetry = __importStar(require("@opentelemetry/api"));
|
|
30
|
+
const tracing_1 = require("@opentelemetry/tracing");
|
|
31
|
+
const graphql_1 = require("graphql");
|
|
32
|
+
var AttributeName;
|
|
10
33
|
(function (AttributeName) {
|
|
11
34
|
AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
|
|
12
35
|
AttributeName["EXECUTION_RESULT"] = "graphql.execute.result";
|
|
@@ -18,12 +41,12 @@ const graphql = require('graphql');
|
|
|
18
41
|
AttributeName["EXECUTION_OPERATION_NAME"] = "graphql.execute.operationName";
|
|
19
42
|
AttributeName["EXECUTION_OPERATION_DOCUMENT"] = "graphql.execute.document";
|
|
20
43
|
AttributeName["EXECUTION_VARIABLES"] = "graphql.execute.variables";
|
|
21
|
-
})(exports.AttributeName || (exports.AttributeName = {}));
|
|
44
|
+
})(AttributeName = exports.AttributeName || (exports.AttributeName = {}));
|
|
22
45
|
const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
|
|
23
|
-
const useOpenTelemetry = (options, tracingProvider, spanKind =
|
|
46
|
+
const useOpenTelemetry = (options, tracingProvider, spanKind = api_1.SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
24
47
|
if (!tracingProvider) {
|
|
25
|
-
tracingProvider = new
|
|
26
|
-
tracingProvider.addSpanProcessor(new
|
|
48
|
+
tracingProvider = new tracing_1.BasicTracerProvider();
|
|
49
|
+
tracingProvider.addSpanProcessor(new tracing_1.SimpleSpanProcessor(new tracing_1.ConsoleSpanExporter()));
|
|
27
50
|
tracingProvider.register();
|
|
28
51
|
}
|
|
29
52
|
const tracer = tracingProvider.getTracer(serviceName);
|
|
@@ -36,16 +59,16 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
36
59
|
const { fieldName, returnType, parentType } = info;
|
|
37
60
|
const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
|
|
38
61
|
attributes: {
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
62
|
+
[AttributeName.RESOLVER_FIELD_NAME]: fieldName,
|
|
63
|
+
[AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
|
|
64
|
+
[AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
|
|
65
|
+
[AttributeName.RESOLVER_ARGS]: JSON.stringify(args || {}),
|
|
43
66
|
},
|
|
44
67
|
}, ctx);
|
|
45
68
|
return ({ result }) => {
|
|
46
69
|
if (result instanceof Error) {
|
|
47
70
|
resolverSpan.recordException({
|
|
48
|
-
name:
|
|
71
|
+
name: AttributeName.RESOLVER_EXCEPTION,
|
|
49
72
|
message: JSON.stringify(result),
|
|
50
73
|
});
|
|
51
74
|
}
|
|
@@ -63,25 +86,25 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
63
86
|
kind: spanKind,
|
|
64
87
|
attributes: {
|
|
65
88
|
...spanAdditionalAttributes,
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
...(options.variables ? { [
|
|
89
|
+
[AttributeName.EXECUTION_OPERATION_NAME]: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
|
|
90
|
+
[AttributeName.EXECUTION_OPERATION_DOCUMENT]: (0, graphql_1.print)(args.document),
|
|
91
|
+
...(options.variables ? { [AttributeName.EXECUTION_VARIABLES]: JSON.stringify((_b = args.variableValues) !== null && _b !== void 0 ? _b : {}) } : {}),
|
|
69
92
|
},
|
|
70
93
|
});
|
|
71
94
|
const resultCbs = {
|
|
72
95
|
onExecuteDone({ result }) {
|
|
73
|
-
if (
|
|
96
|
+
if ((0, core_1.isAsyncIterable)(result)) {
|
|
74
97
|
executionSpan.end();
|
|
75
98
|
// eslint-disable-next-line no-console
|
|
76
99
|
console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
77
100
|
return;
|
|
78
101
|
}
|
|
79
102
|
if (result.data && options.result) {
|
|
80
|
-
executionSpan.setAttribute(
|
|
103
|
+
executionSpan.setAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(result));
|
|
81
104
|
}
|
|
82
105
|
if (result.errors && result.errors.length > 0) {
|
|
83
106
|
executionSpan.recordException({
|
|
84
|
-
name:
|
|
107
|
+
name: AttributeName.EXECUTION_ERROR,
|
|
85
108
|
message: JSON.stringify(result.errors),
|
|
86
109
|
});
|
|
87
110
|
}
|
|
@@ -97,5 +120,4 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
97
120
|
},
|
|
98
121
|
};
|
|
99
122
|
};
|
|
100
|
-
|
|
101
123
|
exports.useOpenTelemetry = useOpenTelemetry;
|
package/package.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/opentelemetry",
|
|
3
|
-
"version": "3.4.0-alpha-
|
|
3
|
+
"version": "3.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
|
},
|
|
9
9
|
"dependencies": {
|
|
@@ -12,26 +12,47 @@
|
|
|
12
12
|
},
|
|
13
13
|
"repository": {
|
|
14
14
|
"type": "git",
|
|
15
|
-
"url": "https://github.com/
|
|
15
|
+
"url": "https://github.com/n1ru4l/envelop.git",
|
|
16
16
|
"directory": "packages/plugins/opentelemetry"
|
|
17
17
|
},
|
|
18
18
|
"author": "Dotan Simha <dotansimha@gmail.com>",
|
|
19
19
|
"license": "MIT",
|
|
20
|
-
"main": "index.js",
|
|
21
|
-
"module": "index.
|
|
22
|
-
"typings": "index.d.ts",
|
|
20
|
+
"main": "cjs/index.js",
|
|
21
|
+
"module": "esm/index.js",
|
|
22
|
+
"typings": "typings/index.d.ts",
|
|
23
23
|
"typescript": {
|
|
24
|
-
"definition": "index.d.ts"
|
|
24
|
+
"definition": "typings/index.d.ts"
|
|
25
25
|
},
|
|
26
|
+
"type": "module",
|
|
26
27
|
"exports": {
|
|
27
28
|
".": {
|
|
28
|
-
"require":
|
|
29
|
-
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./typings/index.d.ts",
|
|
31
|
+
"default": "./cjs/index.js"
|
|
32
|
+
},
|
|
33
|
+
"import": {
|
|
34
|
+
"types": "./typings/index.d.ts",
|
|
35
|
+
"default": "./esm/index.js"
|
|
36
|
+
},
|
|
37
|
+
"default": {
|
|
38
|
+
"types": "./typings/index.d.ts",
|
|
39
|
+
"default": "./esm/index.js"
|
|
40
|
+
}
|
|
30
41
|
},
|
|
31
42
|
"./*": {
|
|
32
|
-
"require":
|
|
33
|
-
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./typings/*.d.ts",
|
|
45
|
+
"default": "./cjs/*.js"
|
|
46
|
+
},
|
|
47
|
+
"import": {
|
|
48
|
+
"types": "./typings/*.d.ts",
|
|
49
|
+
"default": "./esm/*.js"
|
|
50
|
+
},
|
|
51
|
+
"default": {
|
|
52
|
+
"types": "./typings/*.d.ts",
|
|
53
|
+
"default": "./esm/*.js"
|
|
54
|
+
}
|
|
34
55
|
},
|
|
35
56
|
"./package.json": "./package.json"
|
|
36
57
|
}
|
|
37
|
-
}
|
|
58
|
+
}
|
|
@@ -23,5 +23,5 @@ export declare type TracingOptions = {
|
|
|
23
23
|
declare type PluginContext = {
|
|
24
24
|
[tracingSpanSymbol]: opentelemetry.Span;
|
|
25
25
|
};
|
|
26
|
-
export declare const useOpenTelemetry: (options: TracingOptions, tracingProvider?: BasicTracerProvider
|
|
26
|
+
export declare const useOpenTelemetry: (options: TracingOptions, tracingProvider?: BasicTracerProvider, spanKind?: SpanKind, spanAdditionalAttributes?: SpanAttributes, serviceName?: string) => Plugin<PluginContext>;
|
|
27
27
|
export {};
|
package/README.md
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
## `@envelop/opentelemetry`
|
|
2
|
-
|
|
3
|
-
This plugins integrates [Open Telemetry](https://opentelemetry.io/) tracing with your GraphQL execution. It also collects GraphQL execution errors and reports it as Exceptions.
|
|
4
|
-
|
|
5
|
-
You can use this plugin with any kind of Open Telemetry [tracer](https://github.com/open-telemetry/opentelemetry-specification/blob/main/specification/trace/api.md#tracer), and integrate it to any tracing/metric platform that supports this standard.
|
|
6
|
-
|
|
7
|
-
## Getting Started
|
|
8
|
-
|
|
9
|
-
```
|
|
10
|
-
yarn add @envelop/opentelemetry
|
|
11
|
-
```
|
|
12
|
-
|
|
13
|
-
## Usage Example
|
|
14
|
-
|
|
15
|
-
By default, this plugin prints the collected telemetry to the console:
|
|
16
|
-
|
|
17
|
-
```ts
|
|
18
|
-
import { envelop } from '@envelop/core';
|
|
19
|
-
import { useOpenTelemetry } from '@envelop/opentelemetry';
|
|
20
|
-
|
|
21
|
-
const getEnveloped = envelop({
|
|
22
|
-
plugins: [
|
|
23
|
-
// ... other plugins ...
|
|
24
|
-
useOpenTelemetry({
|
|
25
|
-
resolvers: true, // Tracks resolvers calls, and tracks resolvers thrown errors
|
|
26
|
-
variables: true, // Includes the operation variables values as part of the metadata collected
|
|
27
|
-
result: true, // Includes execution result object as part of the metadata collected
|
|
28
|
-
}),
|
|
29
|
-
],
|
|
30
|
-
});
|
|
31
|
-
```
|
|
32
|
-
|
|
33
|
-
If you wish to use custom tracer/exporter, create it and pass it. This example integrates Jaeger tracer:
|
|
34
|
-
|
|
35
|
-
```ts
|
|
36
|
-
import { envelop } from '@envelop/core';
|
|
37
|
-
import { useOpenTelemetry } from '@envelop/opentelemetry';
|
|
38
|
-
import { JaegerExporter } from '@opentelemetry/exporter-jaeger';
|
|
39
|
-
import { SimpleSpanProcessor, BasicTracerProvider } from '@opentelemetry/tracing';
|
|
40
|
-
|
|
41
|
-
const exporter = new JaegerExporter({
|
|
42
|
-
serviceName: 'my-service-name',
|
|
43
|
-
});
|
|
44
|
-
|
|
45
|
-
const provider = new BasicTracerProvider();
|
|
46
|
-
provider.addSpanProcessor(new SimpleSpanProcessor(exporter));
|
|
47
|
-
provider.register();
|
|
48
|
-
|
|
49
|
-
const getEnveloped = envelop({
|
|
50
|
-
plugins: [
|
|
51
|
-
// ... other plugins ...
|
|
52
|
-
useOpenTelemetry(
|
|
53
|
-
{
|
|
54
|
-
resolvers: true, // Tracks resolvers calls, and tracks resolvers thrown errors
|
|
55
|
-
variables: true, // Includes the operation variables values as part of the metadata collected
|
|
56
|
-
result: true, // Includes execution result object as part of the metadata collected
|
|
57
|
-
},
|
|
58
|
-
provider
|
|
59
|
-
),
|
|
60
|
-
],
|
|
61
|
-
});
|
|
62
|
-
```
|