@envelop/opentelemetry 4.0.0-alpha-4ba70ab.0 → 4.0.0-alpha-d0d0776.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.
Files changed (3) hide show
  1. package/index.js +24 -4
  2. package/index.mjs +7 -7
  3. package/package.json +19 -7
package/index.js CHANGED
@@ -7,6 +7,27 @@ const opentelemetry = require('@opentelemetry/api');
7
7
  const tracing = require('@opentelemetry/tracing');
8
8
  const graphql = require('graphql');
9
9
 
10
+ function _interopNamespace(e) {
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;
10
31
  (function (AttributeName) {
11
32
  AttributeName["EXECUTION_ERROR"] = "graphql.execute.error";
12
33
  AttributeName["EXECUTION_RESULT"] = "graphql.execute.result";
@@ -32,7 +53,7 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
32
53
  ? ({ info, context, args }) => {
33
54
  if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
34
55
  tracer.getActiveSpanProcessor();
35
- const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
56
+ const ctx = opentelemetry__namespace.trace.setSpan(opentelemetry__namespace.context.active(), context[tracingSpanSymbol]);
36
57
  const { fieldName, returnType, parentType } = info;
37
58
  const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
38
59
  attributes: {
@@ -58,14 +79,13 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
58
79
  }
59
80
  : undefined,
60
81
  onExecute({ args, extendContext }) {
61
- var _a, _b;
62
82
  const executionSpan = tracer.startSpan(`${args.operationName || 'Anonymous Operation'}`, {
63
83
  kind: spanKind,
64
84
  attributes: {
65
85
  ...spanAdditionalAttributes,
66
- [exports.AttributeName.EXECUTION_OPERATION_NAME]: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
86
+ [exports.AttributeName.EXECUTION_OPERATION_NAME]: args.operationName ?? undefined,
67
87
  [exports.AttributeName.EXECUTION_OPERATION_DOCUMENT]: graphql.print(args.document),
68
- ...(options.variables ? { [exports.AttributeName.EXECUTION_VARIABLES]: JSON.stringify((_b = args.variableValues) !== null && _b !== void 0 ? _b : {}) } : {}),
88
+ ...(options.variables ? { [exports.AttributeName.EXECUTION_VARIABLES]: JSON.stringify(args.variableValues ?? {}) } : {}),
69
89
  },
70
90
  });
71
91
  const resultCbs = {
package/index.mjs CHANGED
@@ -1,5 +1,6 @@
1
1
  import { isAsyncIterable } from '@envelop/core';
2
- import { SpanKind, trace, context } from '@opentelemetry/api';
2
+ import * as opentelemetry from '@opentelemetry/api';
3
+ import { SpanKind } from '@opentelemetry/api';
3
4
  import { BasicTracerProvider, SimpleSpanProcessor, ConsoleSpanExporter } from '@opentelemetry/tracing';
4
5
  import { print } from 'graphql';
5
6
 
@@ -26,10 +27,10 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
26
27
  const tracer = tracingProvider.getTracer(serviceName);
27
28
  return {
28
29
  onResolverCalled: options.resolvers
29
- ? ({ info, context: context$1, args }) => {
30
- if (context$1 && typeof context$1 === 'object' && context$1[tracingSpanSymbol]) {
30
+ ? ({ info, context, args }) => {
31
+ if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
31
32
  tracer.getActiveSpanProcessor();
32
- const ctx = trace.setSpan(context.active(), context$1[tracingSpanSymbol]);
33
+ const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
33
34
  const { fieldName, returnType, parentType } = info;
34
35
  const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
35
36
  attributes: {
@@ -55,14 +56,13 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
55
56
  }
56
57
  : undefined,
57
58
  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]: (_a = args.operationName) !== null && _a !== void 0 ? _a : undefined,
63
+ [AttributeName.EXECUTION_OPERATION_NAME]: args.operationName ?? undefined,
64
64
  [AttributeName.EXECUTION_OPERATION_DOCUMENT]: print(args.document),
65
- ...(options.variables ? { [AttributeName.EXECUTION_VARIABLES]: JSON.stringify((_b = args.variableValues) !== null && _b !== void 0 ? _b : {}) } : {}),
65
+ ...(options.variables ? { [AttributeName.EXECUTION_VARIABLES]: JSON.stringify(args.variableValues ?? {}) } : {}),
66
66
  },
67
67
  });
68
68
  const resultCbs = {
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/opentelemetry",
3
- "version": "4.0.0-alpha-4ba70ab.0",
3
+ "version": "4.0.0-alpha-d0d0776.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "2.1.0-alpha-4ba70ab.0",
6
+ "@envelop/core": "3.0.0-alpha-d0d0776.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {
@@ -12,7 +12,7 @@
12
12
  },
13
13
  "repository": {
14
14
  "type": "git",
15
- "url": "https://github.com/dotansimha/envelop.git",
15
+ "url": "https://github.com/n1ru4l/envelop.git",
16
16
  "directory": "packages/plugins/opentelemetry"
17
17
  },
18
18
  "author": "Dotan Simha <dotansimha@gmail.com>",
@@ -25,12 +25,24 @@
25
25
  },
26
26
  "exports": {
27
27
  ".": {
28
- "require": "./index.js",
29
- "import": "./index.mjs"
28
+ "require": {
29
+ "default": "./index.js",
30
+ "types": "./index.d.ts"
31
+ },
32
+ "import": {
33
+ "default": "./index.mjs",
34
+ "types": "./index.d.ts"
35
+ }
30
36
  },
31
37
  "./*": {
32
- "require": "./*.js",
33
- "import": "./*.mjs"
38
+ "require": {
39
+ "default": "./*.js",
40
+ "types": "./*.d.ts"
41
+ },
42
+ "import": {
43
+ "default": "./*.mjs",
44
+ "types": "./*.d.ts"
45
+ }
34
46
  },
35
47
  "./package.json": "./package.json"
36
48
  }