@envelop/opentelemetry 3.0.0-alpha-25d99ca.0 → 3.0.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 +29 -27
  2. package/index.mjs +29 -27
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -28,6 +28,35 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
28
28
  }
29
29
  const tracer = tracingProvider.getTracer(serviceName);
30
30
  return {
31
+ onResolverCalled: options.resolvers
32
+ ? ({ info, context, args }) => {
33
+ if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
34
+ tracer.getActiveSpanProcessor();
35
+ const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
36
+ const { fieldName, returnType, parentType } = info;
37
+ const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
38
+ attributes: {
39
+ [exports.AttributeName.RESOLVER_FIELD_NAME]: fieldName,
40
+ [exports.AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
41
+ [exports.AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
42
+ [exports.AttributeName.RESOLVER_ARGS]: JSON.stringify(args || {}),
43
+ },
44
+ }, ctx);
45
+ return ({ result }) => {
46
+ if (result instanceof Error) {
47
+ resolverSpan.recordException({
48
+ name: exports.AttributeName.RESOLVER_EXCEPTION,
49
+ message: JSON.stringify(result),
50
+ });
51
+ }
52
+ else {
53
+ resolverSpan.end();
54
+ }
55
+ };
56
+ }
57
+ return () => { };
58
+ }
59
+ : undefined,
31
60
  onExecute({ args, extendContext }) {
32
61
  var _a, _b;
33
62
  const executionSpan = tracer.startSpan(`${args.operationName || 'Anonymous Operation'}`, {
@@ -63,33 +92,6 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = opentelemetry.Spa
63
92
  extendContext({
64
93
  [tracingSpanSymbol]: executionSpan,
65
94
  });
66
- resultCbs.onResolverCalled = ({ info, context }) => {
67
- if (context && typeof context === 'object' && context[tracingSpanSymbol]) {
68
- tracer.getActiveSpanProcessor();
69
- const ctx = opentelemetry.trace.setSpan(opentelemetry.context.active(), context[tracingSpanSymbol]);
70
- const { fieldName, returnType, parentType } = info;
71
- const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
72
- attributes: {
73
- [exports.AttributeName.RESOLVER_FIELD_NAME]: fieldName,
74
- [exports.AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
75
- [exports.AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
76
- [exports.AttributeName.RESOLVER_ARGS]: JSON.stringify(args || {}),
77
- },
78
- }, ctx);
79
- return ({ result }) => {
80
- if (result instanceof Error) {
81
- resolverSpan.recordException({
82
- name: exports.AttributeName.RESOLVER_EXCEPTION,
83
- message: JSON.stringify(result),
84
- });
85
- }
86
- else {
87
- resolverSpan.end();
88
- }
89
- };
90
- }
91
- return () => { };
92
- };
93
95
  }
94
96
  return resultCbs;
95
97
  },
package/index.mjs CHANGED
@@ -25,6 +25,35 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
25
25
  }
26
26
  const tracer = tracingProvider.getTracer(serviceName);
27
27
  return {
28
+ onResolverCalled: options.resolvers
29
+ ? ({ info, context: context$1, args }) => {
30
+ if (context$1 && typeof context$1 === 'object' && context$1[tracingSpanSymbol]) {
31
+ tracer.getActiveSpanProcessor();
32
+ const ctx = trace.setSpan(context.active(), context$1[tracingSpanSymbol]);
33
+ const { fieldName, returnType, parentType } = info;
34
+ const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
35
+ attributes: {
36
+ [AttributeName.RESOLVER_FIELD_NAME]: fieldName,
37
+ [AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
38
+ [AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
39
+ [AttributeName.RESOLVER_ARGS]: JSON.stringify(args || {}),
40
+ },
41
+ }, ctx);
42
+ return ({ result }) => {
43
+ if (result instanceof Error) {
44
+ resolverSpan.recordException({
45
+ name: AttributeName.RESOLVER_EXCEPTION,
46
+ message: JSON.stringify(result),
47
+ });
48
+ }
49
+ else {
50
+ resolverSpan.end();
51
+ }
52
+ };
53
+ }
54
+ return () => { };
55
+ }
56
+ : undefined,
28
57
  onExecute({ args, extendContext }) {
29
58
  var _a, _b;
30
59
  const executionSpan = tracer.startSpan(`${args.operationName || 'Anonymous Operation'}`, {
@@ -60,33 +89,6 @@ const useOpenTelemetry = (options, tracingProvider, spanKind = SpanKind.SERVER,
60
89
  extendContext({
61
90
  [tracingSpanSymbol]: executionSpan,
62
91
  });
63
- resultCbs.onResolverCalled = ({ info, context: context$1 }) => {
64
- if (context$1 && typeof context$1 === 'object' && context$1[tracingSpanSymbol]) {
65
- tracer.getActiveSpanProcessor();
66
- const ctx = trace.setSpan(context.active(), context$1[tracingSpanSymbol]);
67
- const { fieldName, returnType, parentType } = info;
68
- const resolverSpan = tracer.startSpan(`${parentType.name}.${fieldName}`, {
69
- attributes: {
70
- [AttributeName.RESOLVER_FIELD_NAME]: fieldName,
71
- [AttributeName.RESOLVER_TYPE_NAME]: parentType.toString(),
72
- [AttributeName.RESOLVER_RESULT_TYPE]: returnType.toString(),
73
- [AttributeName.RESOLVER_ARGS]: JSON.stringify(args || {}),
74
- },
75
- }, ctx);
76
- return ({ result }) => {
77
- if (result instanceof Error) {
78
- resolverSpan.recordException({
79
- name: AttributeName.RESOLVER_EXCEPTION,
80
- message: JSON.stringify(result),
81
- });
82
- }
83
- else {
84
- resolverSpan.end();
85
- }
86
- };
87
- }
88
- return () => { };
89
- };
90
92
  }
91
93
  return resultCbs;
92
94
  },
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@envelop/opentelemetry",
3
- "version": "3.0.0-alpha-25d99ca.0",
3
+ "version": "3.0.0",
4
4
  "sideEffects": false,
5
5
  "peerDependencies": {
6
- "@envelop/core": "1.8.0-alpha-25d99ca.0",
6
+ "@envelop/core": "^2.0.0",
7
7
  "graphql": "^14.0.0 || ^15.0.0 || ^16.0.0"
8
8
  },
9
9
  "dependencies": {