@opentelemetry/api 1.7.0 → 1.8.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/build/esm/experimental/index.d.ts +3 -0
- package/build/esm/experimental/index.js +17 -0
- package/build/esm/experimental/index.js.map +1 -0
- package/build/esm/experimental/trace/SugaredOptions.d.ts +13 -0
- package/build/esm/experimental/trace/SugaredOptions.js +17 -0
- package/build/esm/experimental/trace/SugaredOptions.js.map +1 -0
- package/build/esm/experimental/trace/SugaredTracer.d.ts +64 -0
- package/build/esm/experimental/trace/SugaredTracer.js +92 -0
- package/build/esm/experimental/trace/SugaredTracer.js.map +1 -0
- package/build/esm/version.d.ts +1 -1
- package/build/esm/version.js +1 -1
- package/build/esm/version.js.map +1 -1
- package/build/esnext/experimental/index.d.ts +3 -0
- package/build/esnext/experimental/index.js +17 -0
- package/build/esnext/experimental/index.js.map +1 -0
- package/build/esnext/experimental/trace/SugaredOptions.d.ts +13 -0
- package/build/esnext/experimental/trace/SugaredOptions.js +17 -0
- package/build/esnext/experimental/trace/SugaredOptions.js.map +1 -0
- package/build/esnext/experimental/trace/SugaredTracer.d.ts +64 -0
- package/build/esnext/experimental/trace/SugaredTracer.js +88 -0
- package/build/esnext/experimental/trace/SugaredTracer.js.map +1 -0
- package/build/esnext/version.d.ts +1 -1
- package/build/esnext/version.js +1 -1
- package/build/esnext/version.js.map +1 -1
- package/build/src/experimental/index.d.ts +3 -0
- package/build/src/experimental/index.js +22 -0
- package/build/src/experimental/index.js.map +1 -0
- package/build/src/experimental/trace/SugaredOptions.d.ts +13 -0
- package/build/src/experimental/trace/SugaredOptions.js +18 -0
- package/build/src/experimental/trace/SugaredOptions.js.map +1 -0
- package/build/src/experimental/trace/SugaredTracer.d.ts +64 -0
- package/build/src/experimental/trace/SugaredTracer.js +93 -0
- package/build/src/experimental/trace/SugaredTracer.js.map +1 -0
- package/build/src/version.d.ts +1 -1
- package/build/src/version.js +1 -1
- package/build/src/version.js.map +1 -1
- package/package.json +19 -5
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export { wrapTracer, SugaredTracer } from './trace/SugaredTracer';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport { wrapTracer, SugaredTracer } from './trace/SugaredTracer';\nexport { SugaredSpanOptions } from './trace/SugaredOptions';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Span, SpanOptions } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Options needed for span creation
|
|
4
|
+
*/
|
|
5
|
+
export interface SugaredSpanOptions extends SpanOptions {
|
|
6
|
+
/**
|
|
7
|
+
* function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.
|
|
8
|
+
* @param e Error which triggered this exception
|
|
9
|
+
* @param span current span from context
|
|
10
|
+
*/
|
|
11
|
+
onException?: (e: Error, span: Span) => void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=SugaredOptions.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=SugaredOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SugaredOptions.js","sourceRoot":"","sources":["../../../../src/experimental/trace/SugaredOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Span, SpanOptions } from '../../';\n\n/**\n * Options needed for span creation\n */\nexport interface SugaredSpanOptions extends SpanOptions {\n /**\n * function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.\n * @param e Error which triggered this exception\n * @param span current span from context\n */\n onException?: (e: Error, span: Span) => void;\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SugaredSpanOptions } from './SugaredOptions';
|
|
2
|
+
import { Context, Span, Tracer } from '../../';
|
|
3
|
+
/**
|
|
4
|
+
* return a new SugaredTracer created from the supplied one
|
|
5
|
+
* @param tracer
|
|
6
|
+
*/
|
|
7
|
+
export declare function wrapTracer(tracer: Tracer): SugaredTracer;
|
|
8
|
+
export declare class SugaredTracer implements Tracer {
|
|
9
|
+
private readonly _tracer;
|
|
10
|
+
constructor(tracer: Tracer);
|
|
11
|
+
startActiveSpan: Tracer['startActiveSpan'];
|
|
12
|
+
startSpan: Tracer['startSpan'];
|
|
13
|
+
/**
|
|
14
|
+
* Starts a new {@link Span} and calls the given function passing it the
|
|
15
|
+
* created span as first argument.
|
|
16
|
+
* Additionally, the new span gets set in context and this context is activated
|
|
17
|
+
* for the duration of the function call.
|
|
18
|
+
* The span will be closed after the function has executed.
|
|
19
|
+
* If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.
|
|
20
|
+
*
|
|
21
|
+
* @param name The name of the span
|
|
22
|
+
* @param [options] SugaredSpanOptions used for span creation
|
|
23
|
+
* @param [context] Context to use to extract parent
|
|
24
|
+
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
25
|
+
* @returns return value of fn
|
|
26
|
+
* @example
|
|
27
|
+
* const something = tracer.withActiveSpan('op', span => {
|
|
28
|
+
* // do some work
|
|
29
|
+
* });
|
|
30
|
+
* @example
|
|
31
|
+
* const something = await tracer.withActiveSpan('op', span => {
|
|
32
|
+
* // do some async work
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
|
36
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
|
37
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
38
|
+
/**
|
|
39
|
+
* Starts a new {@link Span} and ends it after execution of fn without setting it on context.
|
|
40
|
+
* The span will be closed after the function has executed.
|
|
41
|
+
* If an exception occurs, it is recorded, the status is et to ERROR and rethrown.
|
|
42
|
+
*
|
|
43
|
+
* This method does NOT modify the current Context.
|
|
44
|
+
*
|
|
45
|
+
* @param name The name of the span
|
|
46
|
+
* @param [options] SugaredSpanOptions used for span creation
|
|
47
|
+
* @param [context] Context to use to extract parent
|
|
48
|
+
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
49
|
+
* @returns Span The newly created span
|
|
50
|
+
* @example
|
|
51
|
+
* const something = tracer.withSpan('op', span => {
|
|
52
|
+
* // do some work
|
|
53
|
+
* });
|
|
54
|
+
* @example
|
|
55
|
+
* const something = await tracer.withSpan('op', span => {
|
|
56
|
+
* // do some async work
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
|
60
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
|
61
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
62
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=SugaredTracer.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { context, SpanStatusCode } from '../../';
|
|
2
|
+
var defaultOnException = function (e, span) {
|
|
3
|
+
span.recordException(e);
|
|
4
|
+
span.setStatus({
|
|
5
|
+
code: SpanStatusCode.ERROR,
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* return a new SugaredTracer created from the supplied one
|
|
10
|
+
* @param tracer
|
|
11
|
+
*/
|
|
12
|
+
export function wrapTracer(tracer) {
|
|
13
|
+
return new SugaredTracer(tracer);
|
|
14
|
+
}
|
|
15
|
+
var SugaredTracer = /** @class */ (function () {
|
|
16
|
+
function SugaredTracer(tracer) {
|
|
17
|
+
this._tracer = tracer;
|
|
18
|
+
this.startSpan = tracer.startSpan.bind(this._tracer);
|
|
19
|
+
this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);
|
|
20
|
+
}
|
|
21
|
+
SugaredTracer.prototype.withActiveSpan = function (name, arg2, arg3, arg4) {
|
|
22
|
+
var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
|
|
23
|
+
return this._tracer.startActiveSpan(name, opts, ctx, function (span) {
|
|
24
|
+
return handleFn(span, opts, fn);
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
SugaredTracer.prototype.withSpan = function (name, arg2, arg3, arg4) {
|
|
28
|
+
var _a = massageParams(arg2, arg3, arg4), opts = _a.opts, ctx = _a.ctx, fn = _a.fn;
|
|
29
|
+
var span = this._tracer.startSpan(name, opts, ctx);
|
|
30
|
+
return handleFn(span, opts, fn);
|
|
31
|
+
};
|
|
32
|
+
return SugaredTracer;
|
|
33
|
+
}());
|
|
34
|
+
export { SugaredTracer };
|
|
35
|
+
/**
|
|
36
|
+
* Massages parameters of withSpan and withActiveSpan to allow signature overwrites
|
|
37
|
+
* @param arg
|
|
38
|
+
* @param arg2
|
|
39
|
+
* @param arg3
|
|
40
|
+
*/
|
|
41
|
+
function massageParams(arg, arg2, arg3) {
|
|
42
|
+
var opts;
|
|
43
|
+
var ctx;
|
|
44
|
+
var fn;
|
|
45
|
+
if (!arg2 && !arg3) {
|
|
46
|
+
fn = arg;
|
|
47
|
+
}
|
|
48
|
+
else if (!arg3) {
|
|
49
|
+
opts = arg;
|
|
50
|
+
fn = arg2;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
opts = arg;
|
|
54
|
+
ctx = arg2;
|
|
55
|
+
fn = arg3;
|
|
56
|
+
}
|
|
57
|
+
opts = opts !== null && opts !== void 0 ? opts : {};
|
|
58
|
+
ctx = ctx !== null && ctx !== void 0 ? ctx : context.active();
|
|
59
|
+
return { opts: opts, ctx: ctx, fn: fn };
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling
|
|
63
|
+
* @param span
|
|
64
|
+
* @param opts
|
|
65
|
+
* @param fn
|
|
66
|
+
*/
|
|
67
|
+
function handleFn(span, opts, fn) {
|
|
68
|
+
var _a;
|
|
69
|
+
var onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
|
|
70
|
+
var errorHandler = function (e) {
|
|
71
|
+
onException(e, span);
|
|
72
|
+
span.end();
|
|
73
|
+
throw e;
|
|
74
|
+
};
|
|
75
|
+
try {
|
|
76
|
+
var ret = fn(span);
|
|
77
|
+
// if fn is an async function, attach a recordException and spanEnd callback to the promise
|
|
78
|
+
if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === 'function') {
|
|
79
|
+
return ret.then(function (val) {
|
|
80
|
+
span.end();
|
|
81
|
+
return val;
|
|
82
|
+
}, errorHandler);
|
|
83
|
+
}
|
|
84
|
+
span.end();
|
|
85
|
+
return ret;
|
|
86
|
+
}
|
|
87
|
+
catch (e) {
|
|
88
|
+
// add throw to signal the compiler that this will throw in the inner scope
|
|
89
|
+
throw errorHandler(e);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
//# sourceMappingURL=SugaredTracer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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AAC,GAAG,EAAE,CAAC;QACX,MAAM,CAAC,CAAC;IACV,CAAC,CAAC;IAEF,IAAI;QACF,IAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAA2B,CAAC;QAC/C,2FAA2F;QAC3F,IAAI,OAAO,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAA,KAAK,UAAU,EAAE;YACnC,OAAO,GAAG,CAAC,IAAI,CAAC,UAAA,GAAG;gBACjB,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,YAAY,CAAkB,CAAC;SACnC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,GAAoB,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,2EAA2E;QAC3E,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC;KACvB;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { SugaredSpanOptions } from './SugaredOptions';\nimport { context, Context, Span, SpanStatusCode, Tracer } from '../../';\n\nconst defaultOnException = (e: Error, span: Span) => {\n span.recordException(e);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n });\n};\n\n/**\n * return a new SugaredTracer created from the supplied one\n * @param tracer\n */\nexport function wrapTracer(tracer: Tracer): SugaredTracer {\n return new SugaredTracer(tracer);\n}\n\nexport class SugaredTracer implements Tracer {\n private readonly _tracer: Tracer;\n\n constructor(tracer: Tracer) {\n this._tracer = tracer;\n this.startSpan = tracer.startSpan.bind(this._tracer);\n this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);\n }\n\n startActiveSpan: Tracer['startActiveSpan'];\n startSpan: Tracer['startSpan'];\n\n /**\n * Starts a new {@link Span} and calls the given function passing it the\n * created span as first argument.\n * Additionally, the new span gets set in context and this context is activated\n * for the duration of the function call.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns return value of fn\n * @example\n * const something = tracer.withActiveSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withActiveSpan('op', span => {\n * // do some async work\n * });\n */\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: F | SugaredSpanOptions,\n arg3?: F | Context,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n return this._tracer.startActiveSpan(name, opts, ctx, (span: Span) =>\n handleFn(span, opts, fn)\n ) as ReturnType<F>;\n }\n\n /**\n * Starts a new {@link Span} and ends it after execution of fn without setting it on context.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is et to ERROR and rethrown.\n *\n * This method does NOT modify the current Context.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns Span The newly created span\n * @example\n * const something = tracer.withSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withSpan('op', span => {\n * // do some async work\n * });\n */\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: SugaredSpanOptions | F,\n arg3?: Context | F,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n const span = this._tracer.startSpan(name, opts, ctx);\n return handleFn(span, opts, fn) as ReturnType<F>;\n }\n}\n\n/**\n * Massages parameters of withSpan and withActiveSpan to allow signature overwrites\n * @param arg\n * @param arg2\n * @param arg3\n */\nfunction massageParams<F extends (span: Span) => ReturnType<F>>(\n arg: F | SugaredSpanOptions,\n arg2?: F | Context,\n arg3?: F\n) {\n let opts: SugaredSpanOptions | undefined;\n let ctx: Context | undefined;\n let fn: F;\n\n if (!arg2 && !arg3) {\n fn = arg as F;\n } else if (!arg3) {\n opts = arg as SugaredSpanOptions;\n fn = arg2 as F;\n } else {\n opts = arg as SugaredSpanOptions;\n ctx = arg2 as Context;\n fn = arg3 as F;\n }\n opts = opts ?? {};\n ctx = ctx ?? context.active();\n\n return { opts, ctx, fn };\n}\n\n/**\n * Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling\n * @param span\n * @param opts\n * @param fn\n */\nfunction handleFn<F extends (span: Span) => ReturnType<F>>(\n span: Span,\n opts: SugaredSpanOptions,\n fn: F\n): ReturnType<F> {\n const onException = opts.onException ?? defaultOnException;\n const errorHandler = (e: Error) => {\n onException(e, span);\n span.end();\n throw e;\n };\n\n try {\n const ret = fn(span) as Promise<ReturnType<F>>;\n // if fn is an async function, attach a recordException and spanEnd callback to the promise\n if (typeof ret?.then === 'function') {\n return ret.then(val => {\n span.end();\n return val;\n }, errorHandler) as ReturnType<F>;\n }\n span.end();\n return ret as ReturnType<F>;\n } catch (e) {\n // add throw to signal the compiler that this will throw in the inner scope\n throw errorHandler(e);\n }\n}\n"]}
|
package/build/esm/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.8.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esm/version.js
CHANGED
package/build/esm/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,IAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.8.0';\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export { wrapTracer, SugaredTracer } from './trace/SugaredTracer';
|
|
17
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport { wrapTracer, SugaredTracer } from './trace/SugaredTracer';\nexport { SugaredSpanOptions } from './trace/SugaredOptions';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Span, SpanOptions } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Options needed for span creation
|
|
4
|
+
*/
|
|
5
|
+
export interface SugaredSpanOptions extends SpanOptions {
|
|
6
|
+
/**
|
|
7
|
+
* function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.
|
|
8
|
+
* @param e Error which triggered this exception
|
|
9
|
+
* @param span current span from context
|
|
10
|
+
*/
|
|
11
|
+
onException?: (e: Error, span: Span) => void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=SugaredOptions.d.ts.map
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Copyright The OpenTelemetry Authors
|
|
3
|
+
*
|
|
4
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
* you may not use this file except in compliance with the License.
|
|
6
|
+
* You may obtain a copy of the License at
|
|
7
|
+
*
|
|
8
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
*
|
|
10
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
* See the License for the specific language governing permissions and
|
|
14
|
+
* limitations under the License.
|
|
15
|
+
*/
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=SugaredOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SugaredOptions.js","sourceRoot":"","sources":["../../../../src/experimental/trace/SugaredOptions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Span, SpanOptions } from '../../';\n\n/**\n * Options needed for span creation\n */\nexport interface SugaredSpanOptions extends SpanOptions {\n /**\n * function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.\n * @param e Error which triggered this exception\n * @param span current span from context\n */\n onException?: (e: Error, span: Span) => void;\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SugaredSpanOptions } from './SugaredOptions';
|
|
2
|
+
import { Context, Span, Tracer } from '../../';
|
|
3
|
+
/**
|
|
4
|
+
* return a new SugaredTracer created from the supplied one
|
|
5
|
+
* @param tracer
|
|
6
|
+
*/
|
|
7
|
+
export declare function wrapTracer(tracer: Tracer): SugaredTracer;
|
|
8
|
+
export declare class SugaredTracer implements Tracer {
|
|
9
|
+
private readonly _tracer;
|
|
10
|
+
constructor(tracer: Tracer);
|
|
11
|
+
startActiveSpan: Tracer['startActiveSpan'];
|
|
12
|
+
startSpan: Tracer['startSpan'];
|
|
13
|
+
/**
|
|
14
|
+
* Starts a new {@link Span} and calls the given function passing it the
|
|
15
|
+
* created span as first argument.
|
|
16
|
+
* Additionally, the new span gets set in context and this context is activated
|
|
17
|
+
* for the duration of the function call.
|
|
18
|
+
* The span will be closed after the function has executed.
|
|
19
|
+
* If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.
|
|
20
|
+
*
|
|
21
|
+
* @param name The name of the span
|
|
22
|
+
* @param [options] SugaredSpanOptions used for span creation
|
|
23
|
+
* @param [context] Context to use to extract parent
|
|
24
|
+
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
25
|
+
* @returns return value of fn
|
|
26
|
+
* @example
|
|
27
|
+
* const something = tracer.withActiveSpan('op', span => {
|
|
28
|
+
* // do some work
|
|
29
|
+
* });
|
|
30
|
+
* @example
|
|
31
|
+
* const something = await tracer.withActiveSpan('op', span => {
|
|
32
|
+
* // do some async work
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
|
36
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
|
37
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
38
|
+
/**
|
|
39
|
+
* Starts a new {@link Span} and ends it after execution of fn without setting it on context.
|
|
40
|
+
* The span will be closed after the function has executed.
|
|
41
|
+
* If an exception occurs, it is recorded, the status is et to ERROR and rethrown.
|
|
42
|
+
*
|
|
43
|
+
* This method does NOT modify the current Context.
|
|
44
|
+
*
|
|
45
|
+
* @param name The name of the span
|
|
46
|
+
* @param [options] SugaredSpanOptions used for span creation
|
|
47
|
+
* @param [context] Context to use to extract parent
|
|
48
|
+
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
49
|
+
* @returns Span The newly created span
|
|
50
|
+
* @example
|
|
51
|
+
* const something = tracer.withSpan('op', span => {
|
|
52
|
+
* // do some work
|
|
53
|
+
* });
|
|
54
|
+
* @example
|
|
55
|
+
* const something = await tracer.withSpan('op', span => {
|
|
56
|
+
* // do some async work
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
|
60
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
|
61
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
62
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=SugaredTracer.d.ts.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { context, SpanStatusCode } from '../../';
|
|
2
|
+
const defaultOnException = (e, span) => {
|
|
3
|
+
span.recordException(e);
|
|
4
|
+
span.setStatus({
|
|
5
|
+
code: SpanStatusCode.ERROR,
|
|
6
|
+
});
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* return a new SugaredTracer created from the supplied one
|
|
10
|
+
* @param tracer
|
|
11
|
+
*/
|
|
12
|
+
export function wrapTracer(tracer) {
|
|
13
|
+
return new SugaredTracer(tracer);
|
|
14
|
+
}
|
|
15
|
+
export class SugaredTracer {
|
|
16
|
+
constructor(tracer) {
|
|
17
|
+
this._tracer = tracer;
|
|
18
|
+
this.startSpan = tracer.startSpan.bind(this._tracer);
|
|
19
|
+
this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);
|
|
20
|
+
}
|
|
21
|
+
withActiveSpan(name, arg2, arg3, arg4) {
|
|
22
|
+
const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);
|
|
23
|
+
return this._tracer.startActiveSpan(name, opts, ctx, (span) => handleFn(span, opts, fn));
|
|
24
|
+
}
|
|
25
|
+
withSpan(name, arg2, arg3, arg4) {
|
|
26
|
+
const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);
|
|
27
|
+
const span = this._tracer.startSpan(name, opts, ctx);
|
|
28
|
+
return handleFn(span, opts, fn);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Massages parameters of withSpan and withActiveSpan to allow signature overwrites
|
|
33
|
+
* @param arg
|
|
34
|
+
* @param arg2
|
|
35
|
+
* @param arg3
|
|
36
|
+
*/
|
|
37
|
+
function massageParams(arg, arg2, arg3) {
|
|
38
|
+
let opts;
|
|
39
|
+
let ctx;
|
|
40
|
+
let fn;
|
|
41
|
+
if (!arg2 && !arg3) {
|
|
42
|
+
fn = arg;
|
|
43
|
+
}
|
|
44
|
+
else if (!arg3) {
|
|
45
|
+
opts = arg;
|
|
46
|
+
fn = arg2;
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
opts = arg;
|
|
50
|
+
ctx = arg2;
|
|
51
|
+
fn = arg3;
|
|
52
|
+
}
|
|
53
|
+
opts = opts !== null && opts !== void 0 ? opts : {};
|
|
54
|
+
ctx = ctx !== null && ctx !== void 0 ? ctx : context.active();
|
|
55
|
+
return { opts, ctx, fn };
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling
|
|
59
|
+
* @param span
|
|
60
|
+
* @param opts
|
|
61
|
+
* @param fn
|
|
62
|
+
*/
|
|
63
|
+
function handleFn(span, opts, fn) {
|
|
64
|
+
var _a;
|
|
65
|
+
const onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
|
|
66
|
+
const errorHandler = (e) => {
|
|
67
|
+
onException(e, span);
|
|
68
|
+
span.end();
|
|
69
|
+
throw e;
|
|
70
|
+
};
|
|
71
|
+
try {
|
|
72
|
+
const ret = fn(span);
|
|
73
|
+
// if fn is an async function, attach a recordException and spanEnd callback to the promise
|
|
74
|
+
if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === 'function') {
|
|
75
|
+
return ret.then(val => {
|
|
76
|
+
span.end();
|
|
77
|
+
return val;
|
|
78
|
+
}, errorHandler);
|
|
79
|
+
}
|
|
80
|
+
span.end();
|
|
81
|
+
return ret;
|
|
82
|
+
}
|
|
83
|
+
catch (e) {
|
|
84
|
+
// add throw to signal the compiler that this will throw in the inner scope
|
|
85
|
+
throw errorHandler(e);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
//# sourceMappingURL=SugaredTracer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SugaredTracer.js","source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G,GAAG,EAAE,CAAC,IAAI,CAA2B,CAAC;QAC/C,2FAA2F;QAC3F,IAAI,OAAO,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAA,KAAK,UAAU,EAAE;YACnC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACpB,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,YAAY,CAAkB,CAAC;SACnC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,GAAoB,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,2EAA2E;QAC3E,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC;KACvB;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { SugaredSpanOptions } from './SugaredOptions';\nimport { context, Context, Span, SpanStatusCode, Tracer } from '../../';\n\nconst defaultOnException = (e: Error, span: Span) => {\n span.recordException(e);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n });\n};\n\n/**\n * return a new SugaredTracer created from the supplied one\n * @param tracer\n */\nexport function wrapTracer(tracer: Tracer): SugaredTracer {\n return new SugaredTracer(tracer);\n}\n\nexport class SugaredTracer implements Tracer {\n private readonly _tracer: Tracer;\n\n constructor(tracer: Tracer) {\n this._tracer = tracer;\n this.startSpan = tracer.startSpan.bind(this._tracer);\n this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);\n }\n\n startActiveSpan: Tracer['startActiveSpan'];\n startSpan: Tracer['startSpan'];\n\n /**\n * Starts a new {@link Span} and calls the given function passing it the\n * created span as first argument.\n * Additionally, the new span gets set in context and this context is activated\n * for the duration of the function call.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns return value of fn\n * @example\n * const something = tracer.withActiveSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withActiveSpan('op', span => {\n * // do some async work\n * });\n */\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: F | SugaredSpanOptions,\n arg3?: F | Context,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n return this._tracer.startActiveSpan(name, opts, ctx, (span: Span) =>\n handleFn(span, opts, fn)\n ) as ReturnType<F>;\n }\n\n /**\n * Starts a new {@link Span} and ends it after execution of fn without setting it on context.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is et to ERROR and rethrown.\n *\n * This method does NOT modify the current Context.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns Span The newly created span\n * @example\n * const something = tracer.withSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withSpan('op', span => {\n * // do some async work\n * });\n */\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: SugaredSpanOptions | F,\n arg3?: Context | F,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n const span = this._tracer.startSpan(name, opts, ctx);\n return handleFn(span, opts, fn) as ReturnType<F>;\n }\n}\n\n/**\n * Massages parameters of withSpan and withActiveSpan to allow signature overwrites\n * @param arg\n * @param arg2\n * @param arg3\n */\nfunction massageParams<F extends (span: Span) => ReturnType<F>>(\n arg: F | SugaredSpanOptions,\n arg2?: F | Context,\n arg3?: F\n) {\n let opts: SugaredSpanOptions | undefined;\n let ctx: Context | undefined;\n let fn: F;\n\n if (!arg2 && !arg3) {\n fn = arg as F;\n } else if (!arg3) {\n opts = arg as SugaredSpanOptions;\n fn = arg2 as F;\n } else {\n opts = arg as SugaredSpanOptions;\n ctx = arg2 as Context;\n fn = arg3 as F;\n }\n opts = opts ?? {};\n ctx = ctx ?? context.active();\n\n return { opts, ctx, fn };\n}\n\n/**\n * Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling\n * @param span\n * @param opts\n * @param fn\n */\nfunction handleFn<F extends (span: Span) => ReturnType<F>>(\n span: Span,\n opts: SugaredSpanOptions,\n fn: F\n): ReturnType<F> {\n const onException = opts.onException ?? defaultOnException;\n const errorHandler = (e: Error) => {\n onException(e, span);\n span.end();\n throw e;\n };\n\n try {\n const ret = fn(span) as Promise<ReturnType<F>>;\n // if fn is an async function, attach a recordException and spanEnd callback to the promise\n if (typeof ret?.then === 'function') {\n return ret.then(val => {\n span.end();\n return val;\n }, errorHandler) as ReturnType<F>;\n }\n span.end();\n return ret as ReturnType<F>;\n } catch (e) {\n // add throw to signal the compiler that this will throw in the inner scope\n throw errorHandler(e);\n }\n}\n"]}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.8.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/esnext/version.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,4DAA4D;AAC5D,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.8.0';\n"]}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SugaredTracer = exports.wrapTracer = void 0;
|
|
4
|
+
/*
|
|
5
|
+
* Copyright The OpenTelemetry Authors
|
|
6
|
+
*
|
|
7
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
8
|
+
* you may not use this file except in compliance with the License.
|
|
9
|
+
* You may obtain a copy of the License at
|
|
10
|
+
*
|
|
11
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
12
|
+
*
|
|
13
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
14
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
15
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
16
|
+
* See the License for the specific language governing permissions and
|
|
17
|
+
* limitations under the License.
|
|
18
|
+
*/
|
|
19
|
+
var SugaredTracer_1 = require("./trace/SugaredTracer");
|
|
20
|
+
Object.defineProperty(exports, "wrapTracer", { enumerable: true, get: function () { return SugaredTracer_1.wrapTracer; } });
|
|
21
|
+
Object.defineProperty(exports, "SugaredTracer", { enumerable: true, get: function () { return SugaredTracer_1.SugaredTracer; } });
|
|
22
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/experimental/index.ts"],"names":[],"mappings":";;;AAAA;;;;;;;;;;;;;;GAcG;AACH,uDAAkE;AAAzD,2GAAA,UAAU,OAAA;AAAE,8GAAA,aAAa,OAAA","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nexport { wrapTracer, SugaredTracer } from './trace/SugaredTracer';\nexport { SugaredSpanOptions } from './trace/SugaredOptions';\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Span, SpanOptions } from '../../';
|
|
2
|
+
/**
|
|
3
|
+
* Options needed for span creation
|
|
4
|
+
*/
|
|
5
|
+
export interface SugaredSpanOptions extends SpanOptions {
|
|
6
|
+
/**
|
|
7
|
+
* function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.
|
|
8
|
+
* @param e Error which triggered this exception
|
|
9
|
+
* @param span current span from context
|
|
10
|
+
*/
|
|
11
|
+
onException?: (e: Error, span: Span) => void;
|
|
12
|
+
}
|
|
13
|
+
//# sourceMappingURL=SugaredOptions.d.ts.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright The OpenTelemetry Authors
|
|
4
|
+
*
|
|
5
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
* you may not use this file except in compliance with the License.
|
|
7
|
+
* You may obtain a copy of the License at
|
|
8
|
+
*
|
|
9
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
*
|
|
11
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
* See the License for the specific language governing permissions and
|
|
15
|
+
* limitations under the License.
|
|
16
|
+
*/
|
|
17
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
18
|
+
//# sourceMappingURL=SugaredOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SugaredOptions.js","sourceRoot":"","sources":["../../../../src/experimental/trace/SugaredOptions.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { Span, SpanOptions } from '../../';\n\n/**\n * Options needed for span creation\n */\nexport interface SugaredSpanOptions extends SpanOptions {\n /**\n * function to overwrite default exception behavior to record the exception. No exceptions should be thrown in the function.\n * @param e Error which triggered this exception\n * @param span current span from context\n */\n onException?: (e: Error, span: Span) => void;\n}\n"]}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { SugaredSpanOptions } from './SugaredOptions';
|
|
2
|
+
import { Context, Span, Tracer } from '../../';
|
|
3
|
+
/**
|
|
4
|
+
* return a new SugaredTracer created from the supplied one
|
|
5
|
+
* @param tracer
|
|
6
|
+
*/
|
|
7
|
+
export declare function wrapTracer(tracer: Tracer): SugaredTracer;
|
|
8
|
+
export declare class SugaredTracer implements Tracer {
|
|
9
|
+
private readonly _tracer;
|
|
10
|
+
constructor(tracer: Tracer);
|
|
11
|
+
startActiveSpan: Tracer['startActiveSpan'];
|
|
12
|
+
startSpan: Tracer['startSpan'];
|
|
13
|
+
/**
|
|
14
|
+
* Starts a new {@link Span} and calls the given function passing it the
|
|
15
|
+
* created span as first argument.
|
|
16
|
+
* Additionally, the new span gets set in context and this context is activated
|
|
17
|
+
* for the duration of the function call.
|
|
18
|
+
* The span will be closed after the function has executed.
|
|
19
|
+
* If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.
|
|
20
|
+
*
|
|
21
|
+
* @param name The name of the span
|
|
22
|
+
* @param [options] SugaredSpanOptions used for span creation
|
|
23
|
+
* @param [context] Context to use to extract parent
|
|
24
|
+
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
25
|
+
* @returns return value of fn
|
|
26
|
+
* @example
|
|
27
|
+
* const something = tracer.withActiveSpan('op', span => {
|
|
28
|
+
* // do some work
|
|
29
|
+
* });
|
|
30
|
+
* @example
|
|
31
|
+
* const something = await tracer.withActiveSpan('op', span => {
|
|
32
|
+
* // do some async work
|
|
33
|
+
* });
|
|
34
|
+
*/
|
|
35
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
|
36
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
|
37
|
+
withActiveSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
38
|
+
/**
|
|
39
|
+
* Starts a new {@link Span} and ends it after execution of fn without setting it on context.
|
|
40
|
+
* The span will be closed after the function has executed.
|
|
41
|
+
* If an exception occurs, it is recorded, the status is et to ERROR and rethrown.
|
|
42
|
+
*
|
|
43
|
+
* This method does NOT modify the current Context.
|
|
44
|
+
*
|
|
45
|
+
* @param name The name of the span
|
|
46
|
+
* @param [options] SugaredSpanOptions used for span creation
|
|
47
|
+
* @param [context] Context to use to extract parent
|
|
48
|
+
* @param fn function called in the context of the span and receives the newly created span as an argument
|
|
49
|
+
* @returns Span The newly created span
|
|
50
|
+
* @example
|
|
51
|
+
* const something = tracer.withSpan('op', span => {
|
|
52
|
+
* // do some work
|
|
53
|
+
* });
|
|
54
|
+
* @example
|
|
55
|
+
* const something = await tracer.withSpan('op', span => {
|
|
56
|
+
* // do some async work
|
|
57
|
+
* });
|
|
58
|
+
*/
|
|
59
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, fn: F): ReturnType<F>;
|
|
60
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, fn: F): ReturnType<F>;
|
|
61
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
62
|
+
withSpan<F extends (span: Span) => ReturnType<F>>(name: string, options: SugaredSpanOptions, context: Context, fn: F): ReturnType<F>;
|
|
63
|
+
}
|
|
64
|
+
//# sourceMappingURL=SugaredTracer.d.ts.map
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SugaredTracer = exports.wrapTracer = void 0;
|
|
4
|
+
const __1 = require("../../");
|
|
5
|
+
const defaultOnException = (e, span) => {
|
|
6
|
+
span.recordException(e);
|
|
7
|
+
span.setStatus({
|
|
8
|
+
code: __1.SpanStatusCode.ERROR,
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
/**
|
|
12
|
+
* return a new SugaredTracer created from the supplied one
|
|
13
|
+
* @param tracer
|
|
14
|
+
*/
|
|
15
|
+
function wrapTracer(tracer) {
|
|
16
|
+
return new SugaredTracer(tracer);
|
|
17
|
+
}
|
|
18
|
+
exports.wrapTracer = wrapTracer;
|
|
19
|
+
class SugaredTracer {
|
|
20
|
+
constructor(tracer) {
|
|
21
|
+
this._tracer = tracer;
|
|
22
|
+
this.startSpan = tracer.startSpan.bind(this._tracer);
|
|
23
|
+
this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);
|
|
24
|
+
}
|
|
25
|
+
withActiveSpan(name, arg2, arg3, arg4) {
|
|
26
|
+
const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);
|
|
27
|
+
return this._tracer.startActiveSpan(name, opts, ctx, (span) => handleFn(span, opts, fn));
|
|
28
|
+
}
|
|
29
|
+
withSpan(name, arg2, arg3, arg4) {
|
|
30
|
+
const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);
|
|
31
|
+
const span = this._tracer.startSpan(name, opts, ctx);
|
|
32
|
+
return handleFn(span, opts, fn);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
exports.SugaredTracer = SugaredTracer;
|
|
36
|
+
/**
|
|
37
|
+
* Massages parameters of withSpan and withActiveSpan to allow signature overwrites
|
|
38
|
+
* @param arg
|
|
39
|
+
* @param arg2
|
|
40
|
+
* @param arg3
|
|
41
|
+
*/
|
|
42
|
+
function massageParams(arg, arg2, arg3) {
|
|
43
|
+
let opts;
|
|
44
|
+
let ctx;
|
|
45
|
+
let fn;
|
|
46
|
+
if (!arg2 && !arg3) {
|
|
47
|
+
fn = arg;
|
|
48
|
+
}
|
|
49
|
+
else if (!arg3) {
|
|
50
|
+
opts = arg;
|
|
51
|
+
fn = arg2;
|
|
52
|
+
}
|
|
53
|
+
else {
|
|
54
|
+
opts = arg;
|
|
55
|
+
ctx = arg2;
|
|
56
|
+
fn = arg3;
|
|
57
|
+
}
|
|
58
|
+
opts = opts !== null && opts !== void 0 ? opts : {};
|
|
59
|
+
ctx = ctx !== null && ctx !== void 0 ? ctx : __1.context.active();
|
|
60
|
+
return { opts, ctx, fn };
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling
|
|
64
|
+
* @param span
|
|
65
|
+
* @param opts
|
|
66
|
+
* @param fn
|
|
67
|
+
*/
|
|
68
|
+
function handleFn(span, opts, fn) {
|
|
69
|
+
var _a;
|
|
70
|
+
const onException = (_a = opts.onException) !== null && _a !== void 0 ? _a : defaultOnException;
|
|
71
|
+
const errorHandler = (e) => {
|
|
72
|
+
onException(e, span);
|
|
73
|
+
span.end();
|
|
74
|
+
throw e;
|
|
75
|
+
};
|
|
76
|
+
try {
|
|
77
|
+
const ret = fn(span);
|
|
78
|
+
// if fn is an async function, attach a recordException and spanEnd callback to the promise
|
|
79
|
+
if (typeof (ret === null || ret === void 0 ? void 0 : ret.then) === 'function') {
|
|
80
|
+
return ret.then(val => {
|
|
81
|
+
span.end();
|
|
82
|
+
return val;
|
|
83
|
+
}, errorHandler);
|
|
84
|
+
}
|
|
85
|
+
span.end();
|
|
86
|
+
return ret;
|
|
87
|
+
}
|
|
88
|
+
catch (e) {
|
|
89
|
+
// add throw to signal the compiler that this will throw in the inner scope
|
|
90
|
+
throw errorHandler(e);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
//# sourceMappingURL=SugaredTracer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SugaredTracer.js","sourceRoot":"","sources":["../../../../src/experimental/trace/SugaredTracer.ts"],"names":[],"mappings":";;;AAgBA,8BAAwE;AAExE,MAAM,kBAAkB,GAAG,CAAC,CAAQ,EAAE,IAAU,EAAE,EAAE;IAClD,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,CAAC,SAAS,CAAC;QACb,IAAI,EAAE,kBAAc,CAAC,KAAK;KAC3B,CAAC,CAAC;AACL,CAAC,CAAC;AAEF;;;GAGG;AACH,SAAgB,UAAU,CAAC,MAAc;IACvC,OAAO,IAAI,aAAa,CAAC,MAAM,CAAC,CAAC;AACnC,CAAC;AAFD,gCAEC;AAED,MAAa,aAAa;IAGxB,YAAY,MAAc;QACxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACrD,IAAI,CAAC,eAAe,GAAG,MAAM,CAAC,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;IACnE,CAAC;IA0CD,cAAc,CACZ,IAAY,EACZ,IAA4B,EAC5B,IAAkB,EAClB,IAAQ;QAER,MAAM,EAAE,IAAI,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,aAAa,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;QAE1D,OAAO,IAAI,C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AS,QAAQ,CACf,IAAU,EACV,IAAwB,EACxB,EAAK;;IAEL,MAAM,WAAW,GAAG,MAAA,IAAI,CAAC,WAAW,mCAAI,kBAAkB,CAAC;IAC3D,MAAM,YAAY,GAAG,CAAC,CAAQ,EAAE,EAAE;QAChC,WAAW,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC;QACrB,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,MAAM,CAAC,CAAC;IACV,CAAC,CAAC;IAEF,IAAI;QACF,MAAM,GAAG,GAAG,EAAE,CAAC,IAAI,CAA2B,CAAC;QAC/C,2FAA2F;QAC3F,IAAI,OAAO,CAAA,GAAG,aAAH,GAAG,uBAAH,GAAG,CAAE,IAAI,CAAA,KAAK,UAAU,EAAE;YACnC,OAAO,GAAG,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE;gBACpB,IAAI,CAAC,GAAG,EAAE,CAAC;gBACX,OAAO,GAAG,CAAC;YACb,CAAC,EAAE,YAAY,CAAkB,CAAC;SACnC;QACD,IAAI,CAAC,GAAG,EAAE,CAAC;QACX,OAAO,GAAoB,CAAC;KAC7B;IAAC,OAAO,CAAC,EAAE;QACV,2EAA2E;QAC3E,MAAM,YAAY,CAAC,CAAC,CAAC,CAAC;KACvB;AACH,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { SugaredSpanOptions } from './SugaredOptions';\nimport { context, Context, Span, SpanStatusCode, Tracer } from '../../';\n\nconst defaultOnException = (e: Error, span: Span) => {\n span.recordException(e);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n });\n};\n\n/**\n * return a new SugaredTracer created from the supplied one\n * @param tracer\n */\nexport function wrapTracer(tracer: Tracer): SugaredTracer {\n return new SugaredTracer(tracer);\n}\n\nexport class SugaredTracer implements Tracer {\n private readonly _tracer: Tracer;\n\n constructor(tracer: Tracer) {\n this._tracer = tracer;\n this.startSpan = tracer.startSpan.bind(this._tracer);\n this.startActiveSpan = tracer.startActiveSpan.bind(this._tracer);\n }\n\n startActiveSpan: Tracer['startActiveSpan'];\n startSpan: Tracer['startSpan'];\n\n /**\n * Starts a new {@link Span} and calls the given function passing it the\n * created span as first argument.\n * Additionally, the new span gets set in context and this context is activated\n * for the duration of the function call.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is set to ERROR and the exception is rethrown.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns return value of fn\n * @example\n * const something = tracer.withActiveSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withActiveSpan('op', span => {\n * // do some async work\n * });\n */\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withActiveSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: F | SugaredSpanOptions,\n arg3?: F | Context,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n return this._tracer.startActiveSpan(name, opts, ctx, (span: Span) =>\n handleFn(span, opts, fn)\n ) as ReturnType<F>;\n }\n\n /**\n * Starts a new {@link Span} and ends it after execution of fn without setting it on context.\n * The span will be closed after the function has executed.\n * If an exception occurs, it is recorded, the status is et to ERROR and rethrown.\n *\n * This method does NOT modify the current Context.\n *\n * @param name The name of the span\n * @param [options] SugaredSpanOptions used for span creation\n * @param [context] Context to use to extract parent\n * @param fn function called in the context of the span and receives the newly created span as an argument\n * @returns Span The newly created span\n * @example\n * const something = tracer.withSpan('op', span => {\n * // do some work\n * });\n * @example\n * const something = await tracer.withSpan('op', span => {\n * // do some async work\n * });\n */\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n options: SugaredSpanOptions,\n context: Context,\n fn: F\n ): ReturnType<F>;\n withSpan<F extends (span: Span) => ReturnType<F>>(\n name: string,\n arg2: SugaredSpanOptions | F,\n arg3?: Context | F,\n arg4?: F\n ): ReturnType<F> {\n const { opts, ctx, fn } = massageParams(arg2, arg3, arg4);\n\n const span = this._tracer.startSpan(name, opts, ctx);\n return handleFn(span, opts, fn) as ReturnType<F>;\n }\n}\n\n/**\n * Massages parameters of withSpan and withActiveSpan to allow signature overwrites\n * @param arg\n * @param arg2\n * @param arg3\n */\nfunction massageParams<F extends (span: Span) => ReturnType<F>>(\n arg: F | SugaredSpanOptions,\n arg2?: F | Context,\n arg3?: F\n) {\n let opts: SugaredSpanOptions | undefined;\n let ctx: Context | undefined;\n let fn: F;\n\n if (!arg2 && !arg3) {\n fn = arg as F;\n } else if (!arg3) {\n opts = arg as SugaredSpanOptions;\n fn = arg2 as F;\n } else {\n opts = arg as SugaredSpanOptions;\n ctx = arg2 as Context;\n fn = arg3 as F;\n }\n opts = opts ?? {};\n ctx = ctx ?? context.active();\n\n return { opts, ctx, fn };\n}\n\n/**\n * Executes fn, returns results and runs onException in the case of exception to allow overwriting of error handling\n * @param span\n * @param opts\n * @param fn\n */\nfunction handleFn<F extends (span: Span) => ReturnType<F>>(\n span: Span,\n opts: SugaredSpanOptions,\n fn: F\n): ReturnType<F> {\n const onException = opts.onException ?? defaultOnException;\n const errorHandler = (e: Error) => {\n onException(e, span);\n span.end();\n throw e;\n };\n\n try {\n const ret = fn(span) as Promise<ReturnType<F>>;\n // if fn is an async function, attach a recordException and spanEnd callback to the promise\n if (typeof ret?.then === 'function') {\n return ret.then(val => {\n span.end();\n return val;\n }, errorHandler) as ReturnType<F>;\n }\n span.end();\n return ret as ReturnType<F>;\n } catch (e) {\n // add throw to signal the compiler that this will throw in the inner scope\n throw errorHandler(e);\n }\n}\n"]}
|
package/build/src/version.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const VERSION = "1.
|
|
1
|
+
export declare const VERSION = "1.8.0";
|
|
2
2
|
//# sourceMappingURL=version.d.ts.map
|
package/build/src/version.js
CHANGED
package/build/src/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../../src/version.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;;;AAEH,4DAA4D;AAC/C,QAAA,OAAO,GAAG,OAAO,CAAC","sourcesContent":["/*\n * Copyright The OpenTelemetry Authors\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n// this is autogenerated file, see scripts/version-update.js\nexport const VERSION = '1.8.0';\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentelemetry/api",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.8.0",
|
|
4
4
|
"description": "Public API for OpenTelemetry",
|
|
5
5
|
"main": "build/src/index.js",
|
|
6
6
|
"module": "build/esm/index.js",
|
|
@@ -12,6 +12,20 @@
|
|
|
12
12
|
"./build/esnext/platform/index.js": "./build/esnext/platform/browser/index.js",
|
|
13
13
|
"./build/src/platform/index.js": "./build/src/platform/browser/index.js"
|
|
14
14
|
},
|
|
15
|
+
"exports": {
|
|
16
|
+
".": {
|
|
17
|
+
"module": "./build/esm/index.js",
|
|
18
|
+
"esnext": "./build/esnext/index.js",
|
|
19
|
+
"types": "./build/src/index.d.ts",
|
|
20
|
+
"default": "./build/src/index.js"
|
|
21
|
+
},
|
|
22
|
+
"./experimental": {
|
|
23
|
+
"module": "./build/esm/experimental/index.js",
|
|
24
|
+
"esnext": "./build/esnext/experimental/index.js",
|
|
25
|
+
"types": "./build/src/experimental/index.d.ts",
|
|
26
|
+
"default": "./build/src/experimental/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
15
29
|
"repository": "open-telemetry/opentelemetry-js",
|
|
16
30
|
"scripts": {
|
|
17
31
|
"clean": "tsc --build --clean tsconfig.json tsconfig.esm.json tsconfig.esnext.json",
|
|
@@ -66,10 +80,10 @@
|
|
|
66
80
|
"access": "public"
|
|
67
81
|
},
|
|
68
82
|
"devDependencies": {
|
|
69
|
-
"@types/mocha": "10.0.
|
|
83
|
+
"@types/mocha": "10.0.6",
|
|
70
84
|
"@types/node": "18.6.5",
|
|
71
85
|
"@types/sinon": "10.0.20",
|
|
72
|
-
"@types/webpack": "
|
|
86
|
+
"@types/webpack": "5.28.5",
|
|
73
87
|
"@types/webpack-env": "1.16.3",
|
|
74
88
|
"babel-plugin-istanbul": "6.1.1",
|
|
75
89
|
"codecov": "3.8.3",
|
|
@@ -91,9 +105,9 @@
|
|
|
91
105
|
"ts-mocha": "10.0.0",
|
|
92
106
|
"typescript": "4.4.4",
|
|
93
107
|
"unionfs": "4.5.1",
|
|
94
|
-
"webpack": "
|
|
108
|
+
"webpack": "5.89.0"
|
|
95
109
|
},
|
|
96
110
|
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/api",
|
|
97
111
|
"sideEffects": false,
|
|
98
|
-
"gitHead": "
|
|
112
|
+
"gitHead": "7be35c7845e206b27b682e8ce1cee850b09cec04"
|
|
99
113
|
}
|