@envelop/opentelemetry 4.0.0-alpha-d0d0776.0 → 4.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 +19 -19
- package/{index.js → cjs/index.js} +29 -47
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +10 -10
- package/package.json +25 -16
- package/{index.d.ts → typings/index.d.ts} +1 -1
package/README.md
CHANGED
|
@@ -15,8 +15,8 @@ yarn add @envelop/opentelemetry
|
|
|
15
15
|
By default, this plugin prints the collected telemetry to the console:
|
|
16
16
|
|
|
17
17
|
```ts
|
|
18
|
-
import { envelop } from '@envelop/core'
|
|
19
|
-
import { useOpenTelemetry } from '@envelop/opentelemetry'
|
|
18
|
+
import { envelop } from '@envelop/core'
|
|
19
|
+
import { useOpenTelemetry } from '@envelop/opentelemetry'
|
|
20
20
|
|
|
21
21
|
const getEnveloped = envelop({
|
|
22
22
|
plugins: [
|
|
@@ -24,27 +24,27 @@ const getEnveloped = envelop({
|
|
|
24
24
|
useOpenTelemetry({
|
|
25
25
|
resolvers: true, // Tracks resolvers calls, and tracks resolvers thrown errors
|
|
26
26
|
variables: true, // Includes the operation variables values as part of the metadata collected
|
|
27
|
-
result: true
|
|
28
|
-
})
|
|
29
|
-
]
|
|
30
|
-
})
|
|
27
|
+
result: true // Includes execution result object as part of the metadata collected
|
|
28
|
+
})
|
|
29
|
+
]
|
|
30
|
+
})
|
|
31
31
|
```
|
|
32
32
|
|
|
33
33
|
If you wish to use custom tracer/exporter, create it and pass it. This example integrates Jaeger tracer:
|
|
34
34
|
|
|
35
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'
|
|
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
40
|
|
|
41
41
|
const exporter = new JaegerExporter({
|
|
42
|
-
serviceName: 'my-service-name'
|
|
43
|
-
})
|
|
42
|
+
serviceName: 'my-service-name'
|
|
43
|
+
})
|
|
44
44
|
|
|
45
|
-
const provider = new BasicTracerProvider()
|
|
46
|
-
provider.addSpanProcessor(new SimpleSpanProcessor(exporter))
|
|
47
|
-
provider.register()
|
|
45
|
+
const provider = new BasicTracerProvider()
|
|
46
|
+
provider.addSpanProcessor(new SimpleSpanProcessor(exporter))
|
|
47
|
+
provider.register()
|
|
48
48
|
|
|
49
49
|
const getEnveloped = envelop({
|
|
50
50
|
plugins: [
|
|
@@ -53,10 +53,10 @@ const getEnveloped = envelop({
|
|
|
53
53
|
{
|
|
54
54
|
resolvers: true, // Tracks resolvers calls, and tracks resolvers thrown errors
|
|
55
55
|
variables: true, // Includes the operation variables values as part of the metadata collected
|
|
56
|
-
result: true
|
|
56
|
+
result: true // Includes execution result object as part of the metadata collected
|
|
57
57
|
},
|
|
58
58
|
provider
|
|
59
|
-
)
|
|
60
|
-
]
|
|
61
|
-
})
|
|
59
|
+
)
|
|
60
|
+
]
|
|
61
|
+
})
|
|
62
62
|
```
|
|
@@ -1,33 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
if (e && e.__esModule) return e;
|
|
12
|
-
const n = Object.create(null);
|
|
13
|
-
if (e) {
|
|
14
|
-
for (const k in e) {
|
|
15
|
-
if (k !== 'default') {
|
|
16
|
-
const d = Object.getOwnPropertyDescriptor(e, k);
|
|
17
|
-
Object.defineProperty(n, k, d.get ? d : {
|
|
18
|
-
enumerable: true,
|
|
19
|
-
get: function () { return e[k]; }
|
|
20
|
-
});
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
}
|
|
24
|
-
n["default"] = e;
|
|
25
|
-
return Object.freeze(n);
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
const opentelemetry__namespace = /*#__PURE__*/_interopNamespace(opentelemetry);
|
|
29
|
-
|
|
30
|
-
exports.AttributeName = void 0;
|
|
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-tools/graphql");
|
|
10
|
+
var AttributeName;
|
|
31
11
|
(function (AttributeName) {
|
|
32
12
|
AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
|
|
33
13
|
AttributeName["EXECUTION_RESULT"] = "graphql.execute.result";
|
|
@@ -39,12 +19,12 @@ exports.AttributeName = void 0;
|
|
|
39
19
|
AttributeName["EXECUTION_OPERATION_NAME"] = "graphql.execute.operationName";
|
|
40
20
|
AttributeName["EXECUTION_OPERATION_DOCUMENT"] = "graphql.execute.document";
|
|
41
21
|
AttributeName["EXECUTION_VARIABLES"] = "graphql.execute.variables";
|
|
42
|
-
})(exports.AttributeName || (exports.AttributeName = {}));
|
|
22
|
+
})(AttributeName = exports.AttributeName || (exports.AttributeName = {}));
|
|
43
23
|
const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
|
|
44
|
-
const useOpenTelemetry = (options, tracingProvider, spanKind =
|
|
24
|
+
const useOpenTelemetry = (options, tracingProvider, spanKind = api_1.SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
45
25
|
if (!tracingProvider) {
|
|
46
|
-
tracingProvider = new
|
|
47
|
-
tracingProvider.addSpanProcessor(new
|
|
26
|
+
tracingProvider = new tracing_1.BasicTracerProvider();
|
|
27
|
+
tracingProvider.addSpanProcessor(new tracing_1.SimpleSpanProcessor(new tracing_1.ConsoleSpanExporter()));
|
|
48
28
|
tracingProvider.register();
|
|
49
29
|
}
|
|
50
30
|
const tracer = tracingProvider.getTracer(serviceName);
|
|
@@ -53,20 +33,20 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
53
33
|
? ({ info, context, args }) => {
|
|
54
34
|
if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
|
|
55
35
|
tracer.getActiveSpanProcessor();
|
|
56
|
-
const ctx =
|
|
36
|
+
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
|
|
57
37
|
const { fieldName, returnType, parentType } = info;
|
|
58
38
|
const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
|
|
59
39
|
attributes: {
|
|
60
|
-
[
|
|
61
|
-
[
|
|
62
|
-
[
|
|
63
|
-
[
|
|
40
|
+
[AttributeName.RESOLVER_FIELD_NAME]: fieldName,
|
|
41
|
+
[AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
|
|
42
|
+
[AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
|
|
43
|
+
[AttributeName.RESOLVER_ARGS]: JSON.stringify(args || {}),
|
|
64
44
|
},
|
|
65
45
|
}, ctx);
|
|
66
46
|
return ({ result }) => {
|
|
67
47
|
if (result instanceof Error) {
|
|
68
48
|
resolverSpan.recordException({
|
|
69
|
-
name:
|
|
49
|
+
name: AttributeName.RESOLVER_EXCEPTION,
|
|
70
50
|
message: JSON.stringify(result),
|
|
71
51
|
});
|
|
72
52
|
}
|
|
@@ -79,29 +59,32 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
79
59
|
}
|
|
80
60
|
: undefined,
|
|
81
61
|
onExecute({ args, extendContext }) {
|
|
62
|
+
var _a, _b;
|
|
82
63
|
const executionSpan = tracer.startSpan(`${args.operationName || 'Anonymous Operation'}`, {
|
|
83
64
|
kind: spanKind,
|
|
84
65
|
attributes: {
|
|
85
66
|
...spanAdditionalAttributes,
|
|
86
|
-
[
|
|
87
|
-
[
|
|
88
|
-
...(options.variables
|
|
67
|
+
[AttributeName.EXECUTION_OPERATION_NAME]: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
|
|
68
|
+
[AttributeName.EXECUTION_OPERATION_DOCUMENT]: (0, graphql_1.print)(args.document),
|
|
69
|
+
...(options.variables
|
|
70
|
+
? { [AttributeName.EXECUTION_VARIABLES]: JSON.stringify((_b = args.variableValues) !== null && _b !== void 0 ? _b : {}) }
|
|
71
|
+
: {}),
|
|
89
72
|
},
|
|
90
73
|
});
|
|
91
74
|
const resultCbs = {
|
|
92
75
|
onExecuteDone({ result }) {
|
|
93
|
-
if (
|
|
76
|
+
if ((0, core_1.isAsyncIterable)(result)) {
|
|
94
77
|
executionSpan.end();
|
|
95
78
|
// eslint-disable-next-line no-console
|
|
96
79
|
console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
97
80
|
return;
|
|
98
81
|
}
|
|
99
82
|
if (result.data && options.result) {
|
|
100
|
-
executionSpan.setAttribute(
|
|
83
|
+
executionSpan.setAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(result));
|
|
101
84
|
}
|
|
102
85
|
if (result.errors && result.errors.length > 0) {
|
|
103
86
|
executionSpan.recordException({
|
|
104
|
-
name:
|
|
87
|
+
name: AttributeName.EXECUTION_ERROR,
|
|
105
88
|
message: JSON.stringify(result.errors),
|
|
106
89
|
});
|
|
107
90
|
}
|
|
@@ -117,5 +100,4 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
117
100
|
},
|
|
118
101
|
};
|
|
119
102
|
};
|
|
120
|
-
|
|
121
103
|
exports.useOpenTelemetry = useOpenTelemetry;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { isAsyncIterable } from '@envelop/core';
|
|
2
|
-
import * as opentelemetry from '@opentelemetry/api';
|
|
3
2
|
import { SpanKind } from '@opentelemetry/api';
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
var AttributeName;
|
|
3
|
+
import * as opentelemetry from '@opentelemetry/api';
|
|
4
|
+
import { BasicTracerProvider, ConsoleSpanExporter, SimpleSpanProcessor } from '@opentelemetry/tracing';
|
|
5
|
+
import { print } from '@graphql-tools/graphql';
|
|
6
|
+
export var AttributeName;
|
|
8
7
|
(function (AttributeName) {
|
|
9
8
|
AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
|
|
10
9
|
AttributeName["EXECUTION_RESULT"] = "graphql.execute.result";
|
|
@@ -18,7 +17,7 @@ var AttributeName;
|
|
|
18
17
|
AttributeName["EXECUTION_VARIABLES"] = "graphql.execute.variables";
|
|
19
18
|
})(AttributeName || (AttributeName = {}));
|
|
20
19
|
const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
|
|
21
|
-
const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
20
|
+
export const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
22
21
|
if (!tracingProvider) {
|
|
23
22
|
tracingProvider = new BasicTracerProvider();
|
|
24
23
|
tracingProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
|
|
@@ -56,13 +55,16 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
|
|
|
56
55
|
}
|
|
57
56
|
: undefined,
|
|
58
57
|
onExecute({ args, extendContext }) {
|
|
58
|
+
var _a, _b;
|
|
59
59
|
const executionSpan = tracer.startSpan(`${args.operationName || 'Anonymous Operation'}`, {
|
|
60
60
|
kind: spanKind,
|
|
61
61
|
attributes: {
|
|
62
62
|
...spanAdditionalAttributes,
|
|
63
|
-
[AttributeName.EXECUTION_OPERATION_NAME]: args.operationName
|
|
63
|
+
[AttributeName.EXECUTION_OPERATION_NAME]: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
|
|
64
64
|
[AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(args.document),
|
|
65
|
-
...(options.variables
|
|
65
|
+
...(options.variables
|
|
66
|
+
? { [AttributeName.EXECUTION_VARIABLES]: JSON.stringify((_b = args.variableValues) !== null && _b !== void 0 ? _b : {}) }
|
|
67
|
+
: {}),
|
|
66
68
|
},
|
|
67
69
|
});
|
|
68
70
|
const resultCbs = {
|
|
@@ -94,5 +96,3 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
|
|
|
94
96
|
},
|
|
95
97
|
};
|
|
96
98
|
};
|
|
97
|
-
|
|
98
|
-
export { AttributeName, useOpenTelemetry };
|
package/package.json
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@envelop/opentelemetry",
|
|
3
|
-
"version": "4.0.0-alpha-
|
|
3
|
+
"version": "4.0.0-alpha-ccec0fc.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "3.0.0-alpha-
|
|
7
|
-
"graphql": "
|
|
6
|
+
"@envelop/core": "3.0.0-alpha-ccec0fc.0",
|
|
7
|
+
"@graphql-tools/graphql": "0.1.0-alpha-e7752ba5.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@opentelemetry/api": "^1.0.0",
|
|
@@ -17,33 +17,42 @@
|
|
|
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
29
|
"require": {
|
|
29
|
-
"
|
|
30
|
-
"
|
|
30
|
+
"types": "./typings/index.d.ts",
|
|
31
|
+
"default": "./cjs/index.js"
|
|
31
32
|
},
|
|
32
33
|
"import": {
|
|
33
|
-
"
|
|
34
|
-
"
|
|
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"
|
|
35
40
|
}
|
|
36
41
|
},
|
|
37
42
|
"./*": {
|
|
38
43
|
"require": {
|
|
39
|
-
"
|
|
40
|
-
"
|
|
44
|
+
"types": "./typings/*.d.ts",
|
|
45
|
+
"default": "./cjs/*.js"
|
|
41
46
|
},
|
|
42
47
|
"import": {
|
|
43
|
-
"
|
|
44
|
-
"
|
|
48
|
+
"types": "./typings/*.d.ts",
|
|
49
|
+
"default": "./esm/*.js"
|
|
50
|
+
},
|
|
51
|
+
"default": {
|
|
52
|
+
"types": "./typings/*.d.ts",
|
|
53
|
+
"default": "./esm/*.js"
|
|
45
54
|
}
|
|
46
55
|
},
|
|
47
56
|
"./package.json": "./package.json"
|
|
48
57
|
}
|
|
49
|
-
}
|
|
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 {};
|