@tramvai/module-opentelemetry 4.41.99
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/README.md +153 -0
- package/lib/browser.d.ts +4 -0
- package/lib/browser.js +15 -0
- package/lib/instrumentation/httpClient.d.ts +11 -0
- package/lib/instrumentation/httpClient.es.js +97 -0
- package/lib/instrumentation/httpClient.js +101 -0
- package/lib/instrumentation/logs.d.ts +4 -0
- package/lib/instrumentation/logs.es.js +27 -0
- package/lib/instrumentation/logs.js +31 -0
- package/lib/instrumentation/server.d.ts +27 -0
- package/lib/instrumentation/server.es.js +125 -0
- package/lib/instrumentation/server.js +135 -0
- package/lib/server.d.ts +4 -0
- package/lib/server.es.js +127 -0
- package/lib/server.js +135 -0
- package/lib/tokens.browser.js +10 -0
- package/lib/tokens.d.ts +41 -0
- package/lib/tokens.es.js +10 -0
- package/lib/tokens.js +19 -0
- package/lib/tracer/tracer.d.ts +18 -0
- package/lib/tracer/tracer.es.js +78 -0
- package/lib/tracer/tracer.js +86 -0
- package/package.json +44 -0
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var isPromise = require('@tinkoff/utils/is/promise');
|
|
6
|
+
var api = require('@opentelemetry/api');
|
|
7
|
+
var errors = require('@tinkoff/errors');
|
|
8
|
+
|
|
9
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
+
|
|
11
|
+
var isPromise__default = /*#__PURE__*/_interopDefaultLegacy(isPromise);
|
|
12
|
+
|
|
13
|
+
/* eslint-disable prefer-destructuring */
|
|
14
|
+
function recordAndThrowError(span, error, { skipError = () => false }) {
|
|
15
|
+
var _a;
|
|
16
|
+
span.recordException(error);
|
|
17
|
+
if (!(skipError(error) || errors.isSilentError(error))) {
|
|
18
|
+
span.setStatus({
|
|
19
|
+
code: api.SpanStatusCode.ERROR,
|
|
20
|
+
message: (_a = error === null || error === void 0 ? void 0 : error.message) !== null && _a !== void 0 ? _a : 'Unknown error',
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
span.end();
|
|
24
|
+
throw error;
|
|
25
|
+
}
|
|
26
|
+
class TramvaiTracerImpl {
|
|
27
|
+
constructor({ tracer }) {
|
|
28
|
+
this.tracer = tracer;
|
|
29
|
+
}
|
|
30
|
+
startSpan(...args) {
|
|
31
|
+
// @ts-expect-error
|
|
32
|
+
return this.tracer.startSpan(...args);
|
|
33
|
+
}
|
|
34
|
+
startActiveSpan(...args) {
|
|
35
|
+
// @ts-expect-error
|
|
36
|
+
return this.tracer.startActiveSpan(...args);
|
|
37
|
+
}
|
|
38
|
+
getActiveSpan() {
|
|
39
|
+
return api.trace.getSpan(api.context.active());
|
|
40
|
+
}
|
|
41
|
+
trace(...args) {
|
|
42
|
+
var _a;
|
|
43
|
+
const name = args[0];
|
|
44
|
+
let fn;
|
|
45
|
+
let options;
|
|
46
|
+
let params;
|
|
47
|
+
if (args.length === 2 || (args.length === 3 && typeof args[2] === 'object')) {
|
|
48
|
+
fn = args[1];
|
|
49
|
+
options = {};
|
|
50
|
+
params = args[2] || {};
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
fn = args[2];
|
|
54
|
+
options = args[1];
|
|
55
|
+
params = args[3] || {};
|
|
56
|
+
}
|
|
57
|
+
const activeSpan = api.trace.getSpan(api.context.active());
|
|
58
|
+
const spanContext = activeSpan ? api.trace.setSpan(api.context.active(), activeSpan) : undefined;
|
|
59
|
+
const ctx = (_a = spanContext !== null && spanContext !== void 0 ? spanContext : api.context.active()) !== null && _a !== void 0 ? _a : api.ROOT_CONTEXT;
|
|
60
|
+
return this.startActiveSpan(name, options, ctx, (span) => {
|
|
61
|
+
try {
|
|
62
|
+
const result = fn(span);
|
|
63
|
+
// wrap promise fn, end span if promise is resolved or rejected
|
|
64
|
+
if (isPromise__default["default"](result)) {
|
|
65
|
+
return result
|
|
66
|
+
.then((res) => {
|
|
67
|
+
span.end();
|
|
68
|
+
return res;
|
|
69
|
+
})
|
|
70
|
+
.catch((error) => {
|
|
71
|
+
recordAndThrowError(span, error, params);
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
// otherwise, end span immediately
|
|
75
|
+
span.end();
|
|
76
|
+
return result;
|
|
77
|
+
}
|
|
78
|
+
catch (error) {
|
|
79
|
+
recordAndThrowError(span, error, params);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
/* eslint-enable prefer-destructuring */
|
|
85
|
+
|
|
86
|
+
exports.TramvaiTracerImpl = TramvaiTracerImpl;
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@tramvai/module-opentelemetry",
|
|
3
|
+
"version": "4.41.99",
|
|
4
|
+
"description": "Интеграция OpenTelemetry",
|
|
5
|
+
"browser": "lib/browser.js",
|
|
6
|
+
"main": "lib/server.js",
|
|
7
|
+
"module": "lib/server.es.js",
|
|
8
|
+
"typings": "lib/server.d.d.ts",
|
|
9
|
+
"files": [
|
|
10
|
+
"lib"
|
|
11
|
+
],
|
|
12
|
+
"sideEffects": false,
|
|
13
|
+
"license": "Apache-2.0",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+ssh://git@github.com/tramvaijs/tramvai.git"
|
|
17
|
+
},
|
|
18
|
+
"scripts": {
|
|
19
|
+
"build": "tramvai-build --forPublish --preserveModules",
|
|
20
|
+
"watch": "tsc -w"
|
|
21
|
+
},
|
|
22
|
+
"publishConfig": {
|
|
23
|
+
"registry": "https://registry.npmjs.org/"
|
|
24
|
+
},
|
|
25
|
+
"dependencies": {
|
|
26
|
+
"@opentelemetry/api": "^1.9.0",
|
|
27
|
+
"@opentelemetry/resources": "^1.28.0",
|
|
28
|
+
"@opentelemetry/sdk-trace-node": "^1.28.0",
|
|
29
|
+
"@opentelemetry/semantic-conventions": "^1.28.0",
|
|
30
|
+
"@tinkoff/errors": "0.5.3",
|
|
31
|
+
"@tinkoff/utils": "^2.1.2",
|
|
32
|
+
"@tramvai/tokens-common": "4.41.99",
|
|
33
|
+
"@tramvai/tokens-http-client": "4.41.99",
|
|
34
|
+
"@tramvai/tokens-metrics": "4.41.99",
|
|
35
|
+
"@tramvai/tokens-server": "4.41.99",
|
|
36
|
+
"@tramvai/tokens-server-private": "4.41.99",
|
|
37
|
+
"path-to-regexp": "0.1.7"
|
|
38
|
+
},
|
|
39
|
+
"peerDependencies": {
|
|
40
|
+
"@tinkoff/dippy": "0.10.11",
|
|
41
|
+
"@tramvai/core": "4.41.99",
|
|
42
|
+
"tslib": "^2.4.0"
|
|
43
|
+
}
|
|
44
|
+
}
|