arvo-core 1.0.19 → 1.0.20
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +4 -0
- package/dist/OpenTelemetry/index.d.ts +10 -7
- package/dist/OpenTelemetry/index.js +14 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
@@ -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: (
|
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 {(
|
48
|
-
* This function will receive the
|
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
|
-
*
|
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 (
|
31
|
-
if (traceparent) {
|
32
|
-
return api_1.propagation.extract(api_1.
|
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 {(
|
99
|
-
* This function will receive the
|
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
|
-
*
|
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.
|
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
|
154
|
+
activeContext = (0, exports.getTelemetryContext)(telemetryContext.carrier);
|
152
155
|
activeTracer = telemetryContext.tracer;
|
153
156
|
}
|
154
157
|
var newSpan = activeTracer.startSpan(spanName, spanOptions, activeContext);
|