@envelop/opentelemetry 4.0.0-alpha-36a1267.0 → 4.0.0-alpha-5b6bfa8.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} +27 -25
- package/cjs/package.json +1 -0
- package/{index.mjs → esm/index.js} +12 -12
- package/package.json +34 -13
- 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,12 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
const
|
|
9
|
-
|
|
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;
|
|
10
11
|
(function (AttributeName) {
|
|
11
12
|
AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
|
|
12
13
|
AttributeName["EXECUTION_RESULT"] = "graphql.execute.result";
|
|
@@ -18,12 +19,12 @@ const graphql = require('graphql');
|
|
|
18
19
|
AttributeName["EXECUTION_OPERATION_NAME"] = "graphql.execute.operationName";
|
|
19
20
|
AttributeName["EXECUTION_OPERATION_DOCUMENT"] = "graphql.execute.document";
|
|
20
21
|
AttributeName["EXECUTION_VARIABLES"] = "graphql.execute.variables";
|
|
21
|
-
})(exports.AttributeName || (exports.AttributeName = {}));
|
|
22
|
+
})(AttributeName = exports.AttributeName || (exports.AttributeName = {}));
|
|
22
23
|
const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
|
|
23
|
-
const useOpenTelemetry = (options, tracingProvider, spanKind =
|
|
24
|
+
const useOpenTelemetry = (options, tracingProvider, spanKind = api_1.SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
24
25
|
if (!tracingProvider) {
|
|
25
|
-
tracingProvider = new
|
|
26
|
-
tracingProvider.addSpanProcessor(new
|
|
26
|
+
tracingProvider = new tracing_1.BasicTracerProvider();
|
|
27
|
+
tracingProvider.addSpanProcessor(new tracing_1.SimpleSpanProcessor(new tracing_1.ConsoleSpanExporter()));
|
|
27
28
|
tracingProvider.register();
|
|
28
29
|
}
|
|
29
30
|
const tracer = tracingProvider.getTracer(serviceName);
|
|
@@ -36,16 +37,16 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
36
37
|
const { fieldName, returnType, parentType } = info;
|
|
37
38
|
const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
|
|
38
39
|
attributes: {
|
|
39
|
-
[
|
|
40
|
-
[
|
|
41
|
-
[
|
|
42
|
-
[
|
|
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 || {}),
|
|
43
44
|
},
|
|
44
45
|
}, ctx);
|
|
45
46
|
return ({ result }) => {
|
|
46
47
|
if (result instanceof Error) {
|
|
47
48
|
resolverSpan.recordException({
|
|
48
|
-
name:
|
|
49
|
+
name: AttributeName.RESOLVER_EXCEPTION,
|
|
49
50
|
message: JSON.stringify(result),
|
|
50
51
|
});
|
|
51
52
|
}
|
|
@@ -63,25 +64,27 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
63
64
|
kind: spanKind,
|
|
64
65
|
attributes: {
|
|
65
66
|
...spanAdditionalAttributes,
|
|
66
|
-
[
|
|
67
|
-
[
|
|
68
|
-
...(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
|
+
: {}),
|
|
69
72
|
},
|
|
70
73
|
});
|
|
71
74
|
const resultCbs = {
|
|
72
75
|
onExecuteDone({ result }) {
|
|
73
|
-
if (
|
|
76
|
+
if ((0, core_1.isAsyncIterable)(result)) {
|
|
74
77
|
executionSpan.end();
|
|
75
78
|
// eslint-disable-next-line no-console
|
|
76
79
|
console.warn(`Plugin "newrelic" encountered a AsyncIterator which is not supported yet, so tracing data is not available for the operation.`);
|
|
77
80
|
return;
|
|
78
81
|
}
|
|
79
82
|
if (result.data && options.result) {
|
|
80
|
-
executionSpan.setAttribute(
|
|
83
|
+
executionSpan.setAttribute(AttributeName.EXECUTION_RESULT, JSON.stringify(result));
|
|
81
84
|
}
|
|
82
85
|
if (result.errors && result.errors.length > 0) {
|
|
83
86
|
executionSpan.recordException({
|
|
84
|
-
name:
|
|
87
|
+
name: AttributeName.EXECUTION_ERROR,
|
|
85
88
|
message: JSON.stringify(result.errors),
|
|
86
89
|
});
|
|
87
90
|
}
|
|
@@ -97,5 +100,4 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
|
|
|
97
100
|
},
|
|
98
101
|
};
|
|
99
102
|
};
|
|
100
|
-
|
|
101
103
|
exports.useOpenTelemetry = useOpenTelemetry;
|
package/cjs/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { isAsyncIterable } from '@envelop/core';
|
|
2
|
-
import { SpanKind
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
var AttributeName;
|
|
2
|
+
import { SpanKind } from '@opentelemetry/api';
|
|
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;
|
|
7
7
|
(function (AttributeName) {
|
|
8
8
|
AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
|
|
9
9
|
AttributeName["EXECUTION_RESULT"] = "graphql.execute.result";
|
|
@@ -17,7 +17,7 @@ var AttributeName;
|
|
|
17
17
|
AttributeName["EXECUTION_VARIABLES"] = "graphql.execute.variables";
|
|
18
18
|
})(AttributeName || (AttributeName = {}));
|
|
19
19
|
const tracingSpanSymbol = Symbol('OPEN_TELEMETRY_GRAPHQL');
|
|
20
|
-
const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
20
|
+
export const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER, spanAdditionalAttributes = {}, serviceName = 'graphql') => {
|
|
21
21
|
if (!tracingProvider) {
|
|
22
22
|
tracingProvider = new BasicTracerProvider();
|
|
23
23
|
tracingProvider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
|
|
@@ -26,10 +26,10 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
|
|
|
26
26
|
const tracer = tracingProvider.getTracer(serviceName);
|
|
27
27
|
return {
|
|
28
28
|
onResolverCalled: options.resolvers
|
|
29
|
-
? ({ info, context
|
|
30
|
-
if (context
|
|
29
|
+
? ({ info, context, args }) => {
|
|
30
|
+
if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
|
|
31
31
|
tracer.getActiveSpanProcessor();
|
|
32
|
-
const ctx = trace.setSpan(context.active(), context
|
|
32
|
+
const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
|
|
33
33
|
const { fieldName, returnType, parentType } = info;
|
|
34
34
|
const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
|
|
35
35
|
attributes: {
|
|
@@ -62,7 +62,9 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
|
|
|
62
62
|
...spanAdditionalAttributes,
|
|
63
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-5b6bfa8.0",
|
|
4
4
|
"sideEffects": false,
|
|
5
5
|
"peerDependencies": {
|
|
6
|
-
"@envelop/core": "
|
|
7
|
-
"graphql": "
|
|
6
|
+
"@envelop/core": "3.0.0-alpha-5b6bfa8.0",
|
|
7
|
+
"@graphql-tools/graphql": "0.1.0-alpha-33fb2950.0"
|
|
8
8
|
},
|
|
9
9
|
"dependencies": {
|
|
10
10
|
"@opentelemetry/api": "^1.0.0",
|
|
@@ -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 {};
|