arvo-core 1.0.18 → 1.0.20

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -36,7 +36,11 @@
36
36
 
37
37
  - Added ArvoEvent spec-ed extension getter for a more ergonomic experience
38
38
 
39
- ## [1.0.18] - 2024-09-07
39
+ ## [1.0.19] - 2024-09-07
40
40
 
41
41
  - Fix a type bug in ArvoEvent creation
42
42
 
43
+ ## [1.0.20] - 2024-09-07
44
+
45
+ - Updated OpenTelemetry
46
+
@@ -44,7 +44,7 @@ export default class ArvoEventFactory<TUri extends string = string, TType extend
44
44
  */
45
45
  emits<U extends keyof TEmits & string, TExtension extends Record<string, any>>(event: CreateArvoEvent<z.infer<TEmits[U]>, U> & {
46
46
  to: string;
47
- }, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<z.TypeOf<z.TypeOf<TEmits[U]>>, TExtension, U>;
47
+ }, extensions?: TExtension, telemetry?: TelemetryContext): import("..").ArvoEvent<z.TypeOf<TEmits[U]>, TExtension, U>;
48
48
  /**
49
49
  * Creates a system error ArvoEvent.
50
50
  *
@@ -5,7 +5,7 @@ import { TelemetryCarrier, TelemetryLogLevel, TelemetryContext } from './types';
5
5
  * @param traceparent - The trace header string.
6
6
  * @returns The active context.
7
7
  */
8
- export declare const getTelemetryContext: (traceparent?: string | null) => Context;
8
+ export declare const getTelemetryContext: (carrier?: TelemetryCarrier) => Context;
9
9
  /**
10
10
  * Parses the context from a span and active context.
11
11
  * @param span - The span to parse the context from.
@@ -42,23 +42,27 @@ export declare const exceptionToSpan: (span: Span, level: TelemetryLogLevel, err
42
42
  * @template TReturn - The return type of the wrapped function.
43
43
  *
44
44
  * @param {TelemetryContext | string} telemetryContext - The OpenTelemetry context object or a tracer name.
45
+ * If a string is provided, it will be used as the tracer name to retrieve the tracer.
46
+ * If a `TelemetryContext` object is provided, it should contain the span, tracer, and carrier information.
45
47
  * @param {string} spanName - The name of the span to be created.
46
- * @param {SpanOptions} [spanOptions] - Optional configuration for the span.
47
- * @param {(currentSpan: Span, ...args: TArgs) => TReturn} wrappedFunction - The function to be executed within the new span.
48
- * This function will receive the current span as its first argument.
48
+ * @param {SpanOptions} [spanOptions] - Optional configuration for the span, such as attributes, links, and sampling.
49
+ * @param {(telemetryContext: TelemetryContext, ...args: TArgs) => TReturn} wrappedFunction - The function to be executed within the new span.
50
+ * This function will receive the `TelemetryContext` object as its first argument, containing the current span, tracer, and carrier.
51
+ * The rest of the arguments will be passed as additional parameters to the wrapped function.
49
52
  * @param {ThisParameterType<TFunction>} [thisArg] - The 'this' context to be used when calling the wrapped function.
50
53
  * @param {...TArgs} args - The arguments to be passed to the wrapped function.
51
54
  *
52
55
  * @returns {TReturn} The result of the wrapped function execution.
53
56
  *
54
57
  * @throws {Error} Rethrows any error that occurs during the execution of the wrapped function.
58
+ * The error will be logged to the span with an 'ERROR' level, and the span status will be set to `SpanStatusCode.ERROR`.
55
59
  *
56
60
  * @example
57
61
  * // Using with TelemetryContext
58
62
  * const telemetryContext: TelemetryContext = {
59
63
  * span: currentSpan,
60
64
  * tracer: currentTracer,
61
- * context: { traceparent: 'traceparent-value', tracestate: 'tracestate-value' }
65
+ * carrier: { traceparent: 'traceparent-value', tracestate: 'tracestate-value' }
62
66
  * };
63
67
  * const result = createOtelSpan(
64
68
  * telemetryContext,
@@ -85,8 +89,7 @@ export declare const exceptionToSpan: (span: Span, level: TelemetryLogLevel, err
85
89
  * null,
86
90
  * '12345'
87
91
  * );
88
- */
89
- export declare const createOtelSpan: <TArgs extends unknown[], TReturn>(telemetryContext: TelemetryContext | string, spanName: string, spanOptions: SpanOptions | undefined, wrappedFunction: (telemetryContext: TelemetryContext, ...args: TArgs) => TReturn, thisArg?: ThisParameterType<typeof wrappedFunction>, ...args: TArgs) => TReturn;
92
+ */ export declare const createOtelSpan: <TArgs extends unknown[], TReturn>(telemetryContext: TelemetryContext | string, spanName: string, spanOptions: SpanOptions | undefined, wrappedFunction: (telemetryContext: TelemetryContext, ...args: TArgs) => TReturn, thisArg?: ThisParameterType<typeof wrappedFunction>, ...args: TArgs) => TReturn;
90
93
  /**
91
94
  * A constant representing a null or not applicable value in OpenTelemetry context.
92
95
  */
@@ -27,9 +27,9 @@ var api_1 = require("@opentelemetry/api");
27
27
  * @param traceparent - The trace header string.
28
28
  * @returns The active context.
29
29
  */
30
- var getTelemetryContext = function (traceparent) {
31
- if (traceparent) {
32
- return api_1.propagation.extract(api_1.context.active(), { traceparent: traceparent });
30
+ var getTelemetryContext = function (carrier) {
31
+ if (carrier && (carrier.traceparent || carrier.tracestate)) {
32
+ return api_1.propagation.extract(api_1.ROOT_CONTEXT, carrier);
33
33
  }
34
34
  return api_1.context.active();
35
35
  };
@@ -93,23 +93,27 @@ exports.exceptionToSpan = exceptionToSpan;
93
93
  * @template TReturn - The return type of the wrapped function.
94
94
  *
95
95
  * @param {TelemetryContext | string} telemetryContext - The OpenTelemetry context object or a tracer name.
96
+ * If a string is provided, it will be used as the tracer name to retrieve the tracer.
97
+ * If a `TelemetryContext` object is provided, it should contain the span, tracer, and carrier information.
96
98
  * @param {string} spanName - The name of the span to be created.
97
- * @param {SpanOptions} [spanOptions] - Optional configuration for the span.
98
- * @param {(currentSpan: Span, ...args: TArgs) => TReturn} wrappedFunction - The function to be executed within the new span.
99
- * This function will receive the current span as its first argument.
99
+ * @param {SpanOptions} [spanOptions] - Optional configuration for the span, such as attributes, links, and sampling.
100
+ * @param {(telemetryContext: TelemetryContext, ...args: TArgs) => TReturn} wrappedFunction - The function to be executed within the new span.
101
+ * This function will receive the `TelemetryContext` object as its first argument, containing the current span, tracer, and carrier.
102
+ * The rest of the arguments will be passed as additional parameters to the wrapped function.
100
103
  * @param {ThisParameterType<TFunction>} [thisArg] - The 'this' context to be used when calling the wrapped function.
101
104
  * @param {...TArgs} args - The arguments to be passed to the wrapped function.
102
105
  *
103
106
  * @returns {TReturn} The result of the wrapped function execution.
104
107
  *
105
108
  * @throws {Error} Rethrows any error that occurs during the execution of the wrapped function.
109
+ * The error will be logged to the span with an 'ERROR' level, and the span status will be set to `SpanStatusCode.ERROR`.
106
110
  *
107
111
  * @example
108
112
  * // Using with TelemetryContext
109
113
  * const telemetryContext: TelemetryContext = {
110
114
  * span: currentSpan,
111
115
  * tracer: currentTracer,
112
- * context: { traceparent: 'traceparent-value', tracestate: 'tracestate-value' }
116
+ * carrier: { traceparent: 'traceparent-value', tracestate: 'tracestate-value' }
113
117
  * };
114
118
  * const result = createOtelSpan(
115
119
  * telemetryContext,
@@ -136,19 +140,18 @@ exports.exceptionToSpan = exceptionToSpan;
136
140
  * null,
137
141
  * '12345'
138
142
  * );
139
- */
140
- var createOtelSpan = function (telemetryContext, spanName, spanOptions, wrappedFunction, thisArg) {
143
+ */ var createOtelSpan = function (telemetryContext, spanName, spanOptions, wrappedFunction, thisArg) {
141
144
  var args = [];
142
145
  for (var _i = 5; _i < arguments.length; _i++) {
143
146
  args[_i - 5] = arguments[_i];
144
147
  }
145
- var activeContext = api_1.context.active();
148
+ var activeContext = api_1.ROOT_CONTEXT;
146
149
  var activeTracer;
147
150
  if (typeof telemetryContext === 'string') {
148
151
  activeTracer = api_1.trace.getTracer(telemetryContext);
149
152
  }
150
153
  else {
151
- activeContext = (0, exports.getTelemetryContext)(telemetryContext.carrier.traceparent);
154
+ activeContext = (0, exports.getTelemetryContext)(telemetryContext.carrier);
152
155
  activeTracer = telemetryContext.tracer;
153
156
  }
154
157
  var newSpan = activeTracer.startSpan(spanName, spanOptions, activeContext);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-core",
3
- "version": "1.0.18",
3
+ "version": "1.0.20",
4
4
  "description": "This core package contains all the core classes and components of the Arvo Event Driven System",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {