@devskin/agent 1.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.
- package/README.md +156 -0
- package/dist/agent.d.ts +28 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +221 -0
- package/dist/agent.js.map +1 -0
- package/dist/api-client.d.ts +14 -0
- package/dist/api-client.d.ts.map +1 -0
- package/dist/api-client.js +102 -0
- package/dist/api-client.js.map +1 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +37 -0
- package/dist/index.js.map +1 -0
- package/dist/instrumentation/express.d.ts +5 -0
- package/dist/instrumentation/express.d.ts.map +1 -0
- package/dist/instrumentation/express.js +100 -0
- package/dist/instrumentation/express.js.map +1 -0
- package/dist/instrumentation/http.d.ts +3 -0
- package/dist/instrumentation/http.d.ts.map +1 -0
- package/dist/instrumentation/http.js +144 -0
- package/dist/instrumentation/http.js.map +1 -0
- package/dist/span.d.ts +21 -0
- package/dist/span.d.ts.map +1 -0
- package/dist/span.js +105 -0
- package/dist/span.js.map +1 -0
- package/dist/types.d.ts +75 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +17 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/context.d.ts +19 -0
- package/dist/utils/context.d.ts.map +1 -0
- package/dist/utils/context.js +42 -0
- package/dist/utils/context.js.map +1 -0
- package/dist/utils/id-generator.d.ts +4 -0
- package/dist/utils/id-generator.d.ts.map +1 -0
- package/dist/utils/id-generator.js +16 -0
- package/dist/utils/id-generator.js.map +1 -0
- package/package.json +46 -0
- package/src/agent.ts +276 -0
- package/src/api-client.ts +125 -0
- package/src/index.ts +32 -0
- package/src/instrumentation/express.ts +143 -0
- package/src/instrumentation/http.ts +180 -0
- package/src/span.ts +178 -0
- package/src/types.ts +128 -0
- package/src/utils/context.ts +87 -0
- package/src/utils/id-generator.ts +22 -0
- package/tsconfig.json +28 -0
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.expressMiddleware = expressMiddleware;
|
|
4
|
+
exports.expressErrorHandler = expressErrorHandler;
|
|
5
|
+
const span_1 = require("../span");
|
|
6
|
+
const context_1 = require("../utils/context");
|
|
7
|
+
function expressMiddleware(agent) {
|
|
8
|
+
const config = agent.getConfig();
|
|
9
|
+
return (req, res, next) => {
|
|
10
|
+
if (!agent.shouldSample()) {
|
|
11
|
+
return next();
|
|
12
|
+
}
|
|
13
|
+
const incomingTraceId = req.headers['x-trace-id'];
|
|
14
|
+
const incomingSpanId = req.headers['x-span-id'];
|
|
15
|
+
const transactionName = req.route?.path
|
|
16
|
+
? `${req.method} ${req.route.path}`
|
|
17
|
+
: `${req.method} ${req.path}`;
|
|
18
|
+
const transaction = new span_1.TransactionBuilder(transactionName, 'http.request', config.serviceName, config.serviceVersion, config.environment, true, agent);
|
|
19
|
+
if (incomingTraceId) {
|
|
20
|
+
transaction.getTransaction().trace_id = incomingTraceId;
|
|
21
|
+
if (incomingSpanId) {
|
|
22
|
+
transaction.getTransaction().parent_span_id = incomingSpanId;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
transaction.setAttributes({
|
|
26
|
+
'http.method': req.method,
|
|
27
|
+
'http.url': req.originalUrl || req.url,
|
|
28
|
+
'http.target': req.path,
|
|
29
|
+
'http.route': req.route?.path,
|
|
30
|
+
'http.host': req.hostname,
|
|
31
|
+
'http.scheme': req.protocol,
|
|
32
|
+
'http.user_agent': req.get('user-agent'),
|
|
33
|
+
'net.peer.ip': req.ip,
|
|
34
|
+
});
|
|
35
|
+
if (Object.keys(req.query).length > 0) {
|
|
36
|
+
transaction.setAttribute('http.query', JSON.stringify(req.query));
|
|
37
|
+
}
|
|
38
|
+
req.devskinTransaction = transaction;
|
|
39
|
+
context_1.Context.run({ transaction: transaction.getTransaction() }, () => {
|
|
40
|
+
const originalSend = res.send;
|
|
41
|
+
const originalJson = res.json;
|
|
42
|
+
const originalEnd = res.end;
|
|
43
|
+
const endTransaction = () => {
|
|
44
|
+
transaction.setAttributes({
|
|
45
|
+
'http.status_code': res.statusCode,
|
|
46
|
+
});
|
|
47
|
+
if (res.statusCode >= 400) {
|
|
48
|
+
transaction.setStatus('error', `HTTP ${res.statusCode}`);
|
|
49
|
+
}
|
|
50
|
+
transaction.setResult(res.statusCode < 400 ? 'success' : 'error');
|
|
51
|
+
transaction.end();
|
|
52
|
+
};
|
|
53
|
+
res.send = function (body) {
|
|
54
|
+
endTransaction();
|
|
55
|
+
return originalSend.call(this, body);
|
|
56
|
+
};
|
|
57
|
+
res.json = function (body) {
|
|
58
|
+
endTransaction();
|
|
59
|
+
return originalJson.call(this, body);
|
|
60
|
+
};
|
|
61
|
+
res.end = function (...args) {
|
|
62
|
+
endTransaction();
|
|
63
|
+
return originalEnd.apply(this, args);
|
|
64
|
+
};
|
|
65
|
+
res.on('error', (error) => {
|
|
66
|
+
transaction.recordError(error);
|
|
67
|
+
endTransaction();
|
|
68
|
+
});
|
|
69
|
+
next();
|
|
70
|
+
});
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
function expressErrorHandler(agent) {
|
|
74
|
+
return (err, req, res, next) => {
|
|
75
|
+
const transaction = req.devskinTransaction;
|
|
76
|
+
if (transaction) {
|
|
77
|
+
transaction.recordError(err);
|
|
78
|
+
transaction.setResult('error');
|
|
79
|
+
transaction.end();
|
|
80
|
+
}
|
|
81
|
+
const config = agent.getConfig();
|
|
82
|
+
agent.reportError({
|
|
83
|
+
timestamp: new Date(),
|
|
84
|
+
message: err.message,
|
|
85
|
+
type: err.name,
|
|
86
|
+
stack_trace: err.stack,
|
|
87
|
+
trace_id: context_1.Context.getTraceId(),
|
|
88
|
+
span_id: context_1.Context.getSpanId(),
|
|
89
|
+
attributes: {
|
|
90
|
+
'http.method': req.method,
|
|
91
|
+
'http.url': req.originalUrl || req.url,
|
|
92
|
+
'http.route': req.route?.path,
|
|
93
|
+
},
|
|
94
|
+
service_name: config.serviceName,
|
|
95
|
+
environment: config.environment,
|
|
96
|
+
});
|
|
97
|
+
next(err);
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=express.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"express.js","sourceRoot":"","sources":["../../src/instrumentation/express.ts"],"names":[],"mappings":";;AAQA,8CAmGC;AAKD,kDA8BC;AA5ID,kCAA6C;AAC7C,8CAA2C;AAK3C,SAAgB,iBAAiB,CAAC,KAAY;IAC5C,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAEjC,OAAO,CAAC,GAAY,EAAE,GAAa,EAAE,IAAkB,EAAE,EAAE;QAEzD,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,EAAE,CAAC;YAC1B,OAAO,IAAI,EAAE,CAAC;QAChB,CAAC;QAGD,MAAM,eAAe,GAAG,GAAG,CAAC,OAAO,CAAC,YAAY,CAAW,CAAC;QAC5D,MAAM,cAAc,GAAG,GAAG,CAAC,OAAO,CAAC,WAAW,CAAW,CAAC;QAG1D,MAAM,eAAe,GAAG,GAAG,CAAC,KAAK,EAAE,IAAI;YACrC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE;YACnC,CAAC,CAAC,GAAG,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,IAAI,EAAE,CAAC;QAEhC,MAAM,WAAW,GAAG,IAAI,yBAAkB,CACxC,eAAe,EACf,cAAc,EACd,MAAM,CAAC,WAAW,EAClB,MAAM,CAAC,cAAc,EACrB,MAAM,CAAC,WAAW,EAClB,IAAI,EACJ,KAAK,CACN,CAAC;QAGF,IAAI,eAAe,EAAE,CAAC;YACpB,WAAW,CAAC,cAAc,EAAE,CAAC,QAAQ,GAAG,eAAe,CAAC;YACxD,IAAI,cAAc,EAAE,CAAC;gBACnB,WAAW,CAAC,c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CAAC;QAGD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACjC,KAAK,CAAC,WAAW,CAAC;YAChB,SAAS,EAAE,IAAI,IAAI,EAAE;YACrB,OAAO,EAAE,GAAG,CAAC,OAAO;YACpB,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,KAAK;YACtB,QAAQ,EAAE,iBAAO,CAAC,UAAU,EAAE;YAC9B,OAAO,EAAE,iBAAO,CAAC,SAAS,EAAE;YAC5B,UAAU,EAAE;gBACV,aAAa,EAAE,GAAG,CAAC,MAAM;gBACzB,UAAU,EAAE,GAAG,CAAC,WAAW,IAAI,GAAG,CAAC,GAAG;gBACtC,YAAY,EAAE,GAAG,CAAC,KAAK,EAAE,IAAI;aAC9B;YACD,YAAY,EAAE,MAAM,CAAC,WAAW;YAChC,WAAW,EAAE,MAAM,CAAC,WAAW;SAChC,CAAC,CAAC;QAEH,IAAI,CAAC,GAAG,CAAC,CAAC;IACZ,CAAC,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/instrumentation/http.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAQjC,wBAAgB,cAAc,CAAC,KAAK,EAAE,KAAK,GAAG,IAAI,CAUjD"}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
exports.instrumentHttp = instrumentHttp;
|
|
37
|
+
const http = __importStar(require("http"));
|
|
38
|
+
const https = __importStar(require("https"));
|
|
39
|
+
const span_1 = require("../span");
|
|
40
|
+
const types_1 = require("../types");
|
|
41
|
+
const context_1 = require("../utils/context");
|
|
42
|
+
function instrumentHttp(agent) {
|
|
43
|
+
const config = agent.getConfig();
|
|
44
|
+
instrumentHttpRequest(http, agent);
|
|
45
|
+
instrumentHttpRequest(https, agent);
|
|
46
|
+
instrumentHttpServer(http, agent);
|
|
47
|
+
instrumentHttpServer(https, agent);
|
|
48
|
+
}
|
|
49
|
+
function instrumentHttpRequest(module, agent) {
|
|
50
|
+
const originalRequest = module.request;
|
|
51
|
+
module.request = function (...args) {
|
|
52
|
+
let options = args[0];
|
|
53
|
+
let callback = args[1];
|
|
54
|
+
if (typeof options === 'string') {
|
|
55
|
+
options = new URL(options);
|
|
56
|
+
}
|
|
57
|
+
const config = agent.getConfig();
|
|
58
|
+
const url = typeof args[0] === 'string' ? args[0] : options.href || `${options.protocol}//${options.host || options.hostname}${options.path}`;
|
|
59
|
+
const span = new span_1.SpanBuilder(`HTTP ${options.method || 'GET'}`, types_1.SpanKind.CLIENT, config.serviceName, config.serviceVersion, config.environment, agent);
|
|
60
|
+
span.setAttributes({
|
|
61
|
+
'http.method': options.method || 'GET',
|
|
62
|
+
'http.url': url,
|
|
63
|
+
'http.target': options.path || '/',
|
|
64
|
+
'net.peer.name': options.hostname || options.host,
|
|
65
|
+
'net.peer.port': options.port,
|
|
66
|
+
});
|
|
67
|
+
const traceId = context_1.Context.getTraceId();
|
|
68
|
+
const spanId = span.getSpan().span_id;
|
|
69
|
+
if (!options.headers) {
|
|
70
|
+
options.headers = {};
|
|
71
|
+
}
|
|
72
|
+
options.headers['x-trace-id'] = traceId;
|
|
73
|
+
options.headers['x-span-id'] = spanId;
|
|
74
|
+
const wrappedCallback = (res) => {
|
|
75
|
+
span.setAttributes({
|
|
76
|
+
'http.status_code': res.statusCode,
|
|
77
|
+
'http.response.size': res.headers['content-length'],
|
|
78
|
+
});
|
|
79
|
+
if (res.statusCode && res.statusCode >= 400) {
|
|
80
|
+
span.setStatus('error', `HTTP ${res.statusCode}`);
|
|
81
|
+
}
|
|
82
|
+
res.on('end', () => {
|
|
83
|
+
span.end();
|
|
84
|
+
});
|
|
85
|
+
if (callback) {
|
|
86
|
+
callback(res);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const req = originalRequest.call(this, options, wrappedCallback);
|
|
90
|
+
req.on('error', (error) => {
|
|
91
|
+
span.recordError(error);
|
|
92
|
+
span.end();
|
|
93
|
+
});
|
|
94
|
+
return req;
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function instrumentHttpServer(module, agent) {
|
|
98
|
+
const originalCreateServer = module.createServer;
|
|
99
|
+
module.createServer = function (...args) {
|
|
100
|
+
const server = originalCreateServer.call(this, ...args);
|
|
101
|
+
const config = agent.getConfig();
|
|
102
|
+
server.on('request', (req, res) => {
|
|
103
|
+
if (!agent.shouldSample()) {
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
const incomingTraceId = req.headers['x-trace-id'];
|
|
107
|
+
const incomingSpanId = req.headers['x-span-id'];
|
|
108
|
+
const transaction = new span_1.TransactionBuilder(`${req.method} ${req.url}`, 'http.request', config.serviceName, config.serviceVersion, config.environment, true, agent);
|
|
109
|
+
if (incomingTraceId) {
|
|
110
|
+
transaction.getTransaction().trace_id = incomingTraceId;
|
|
111
|
+
if (incomingSpanId) {
|
|
112
|
+
transaction.getTransaction().parent_span_id = incomingSpanId;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
transaction.setAttributes({
|
|
116
|
+
'http.method': req.method,
|
|
117
|
+
'http.url': req.url,
|
|
118
|
+
'http.target': req.url,
|
|
119
|
+
'http.host': req.headers.host,
|
|
120
|
+
'http.scheme': req.protocol || 'http',
|
|
121
|
+
'http.user_agent': req.headers['user-agent'],
|
|
122
|
+
'net.peer.ip': req.socket.remoteAddress,
|
|
123
|
+
'net.peer.port': req.socket.remotePort,
|
|
124
|
+
});
|
|
125
|
+
context_1.Context.run({ transaction: transaction.getTransaction() }, () => {
|
|
126
|
+
const originalEnd = res.end;
|
|
127
|
+
res.end = function (...endArgs) {
|
|
128
|
+
transaction.setAttributes({
|
|
129
|
+
'http.status_code': res.statusCode,
|
|
130
|
+
'http.response.size': res.getHeader('content-length'),
|
|
131
|
+
});
|
|
132
|
+
if (res.statusCode >= 400) {
|
|
133
|
+
transaction.setStatus('error', `HTTP ${res.statusCode}`);
|
|
134
|
+
}
|
|
135
|
+
transaction.setResult(res.statusCode < 400 ? 'success' : 'error');
|
|
136
|
+
transaction.end();
|
|
137
|
+
return originalEnd.call(this, ...endArgs);
|
|
138
|
+
};
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
return server;
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
//# sourceMappingURL=http.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http.js","sourceRoot":"","sources":["../../src/instrumentation/http.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAUA,wCAUC;AApBD,2CAA6B;AAC7B,6CAA+B;AAE/B,kCAA0D;AAC1D,oCAAoC;AACpC,8CAA2C;AAK3C,SAAgB,cAAc,CAAC,KAAY;IACzC,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;IAGjC,qBAAqB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IACnC,qBAAqB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;IAGpC,oBAAoB,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;IAClC,oBAAoB,CAAC,KAAK,EAAE,KAAK,CAAC,CAAC;AACrC,CAAC;AAKD,SAAS,qBAAqB,CAAC,MAAkC,EAAE,KAAY;IAC7E,MAAM,eAAe,GAAG,MAAM,CAAC,OAAO,CAAC;IAEtC,MAAc,CAAC,OAAO,GAAG,UAExB,GAAG,IAAW;QAEd,IAAI,OAAO,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QACtB,IAAI,QAAQ,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;QAGvB,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YAChC,OAAO,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,CAAC;QAC7B,CAAC;QAGD,MAAM,MAAM,GAAG,KAAK,CAAC,SAAS,EAAE,CAAC;QACjC,MAAM,GAAG,GAAG,OAAO,IAAI,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC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GAAG,EAAE,CAAC;wBAC1B,WAAW,CAAC,SAAS,CAAC,OAAc,EAAE,QAAQ,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;oBAClE,CAAC;oBAED,WAAW,CAAC,SAAS,CAAC,GAAG,CAAC,UAAU,GAAG,GAAG,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;oBAClE,WAAW,CAAC,GAAG,EAAE,CAAC;oBAElB,OAAO,WAAW,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,CAAC;gBAC5C,CAAC,CAAC;YACJ,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC;IAChB,CAAC,CAAC;AACJ,CAAC"}
|
package/dist/span.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Span, SpanKind, SpanStatus, Transaction } from './types';
|
|
2
|
+
export declare class SpanBuilder {
|
|
3
|
+
private span;
|
|
4
|
+
private agent;
|
|
5
|
+
constructor(name: string, kind: SpanKind, serviceName: string, serviceVersion?: string, environment?: string, agent?: any);
|
|
6
|
+
setAttribute(key: string, value: any): this;
|
|
7
|
+
setAttributes(attributes: Record<string, any>): this;
|
|
8
|
+
addEvent(name: string, attributes?: Record<string, any>): this;
|
|
9
|
+
setStatus(status: SpanStatus, message?: string): this;
|
|
10
|
+
recordError(error: Error): this;
|
|
11
|
+
end(): void;
|
|
12
|
+
getSpan(): Span;
|
|
13
|
+
}
|
|
14
|
+
export declare class TransactionBuilder extends SpanBuilder {
|
|
15
|
+
private transaction;
|
|
16
|
+
constructor(name: string, type: string, serviceName: string, serviceVersion?: string, environment?: string, sampled?: boolean, agent?: any);
|
|
17
|
+
setResult(result: string): this;
|
|
18
|
+
end(): void;
|
|
19
|
+
getTransaction(): Transaction;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=span.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"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|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.TransactionBuilder = exports.SpanBuilder = void 0;
|
|
4
|
+
const types_1 = require("./types");
|
|
5
|
+
const id_generator_1 = require("./utils/id-generator");
|
|
6
|
+
const context_1 = require("./utils/context");
|
|
7
|
+
class SpanBuilder {
|
|
8
|
+
constructor(name, kind, serviceName, serviceVersion, environment, agent) {
|
|
9
|
+
const parentSpan = context_1.Context.getCurrentSpan();
|
|
10
|
+
const traceId = context_1.Context.getTraceId() || (0, id_generator_1.generateTraceId)();
|
|
11
|
+
this.span = {
|
|
12
|
+
span_id: (0, id_generator_1.generateSpanId)(),
|
|
13
|
+
trace_id: traceId,
|
|
14
|
+
parent_span_id: parentSpan?.span_id,
|
|
15
|
+
name,
|
|
16
|
+
kind,
|
|
17
|
+
start_time: new Date(),
|
|
18
|
+
status: types_1.SpanStatus.OK,
|
|
19
|
+
attributes: {},
|
|
20
|
+
events: [],
|
|
21
|
+
service_name: serviceName,
|
|
22
|
+
service_version: serviceVersion,
|
|
23
|
+
environment,
|
|
24
|
+
};
|
|
25
|
+
this.agent = agent;
|
|
26
|
+
context_1.Context.setSpan(this.span);
|
|
27
|
+
}
|
|
28
|
+
setAttribute(key, value) {
|
|
29
|
+
this.span.attributes[key] = value;
|
|
30
|
+
return this;
|
|
31
|
+
}
|
|
32
|
+
setAttributes(attributes) {
|
|
33
|
+
Object.assign(this.span.attributes, attributes);
|
|
34
|
+
return this;
|
|
35
|
+
}
|
|
36
|
+
addEvent(name, attributes) {
|
|
37
|
+
this.span.events.push({
|
|
38
|
+
timestamp: new Date(),
|
|
39
|
+
name,
|
|
40
|
+
attributes,
|
|
41
|
+
});
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
setStatus(status, message) {
|
|
45
|
+
this.span.status = status;
|
|
46
|
+
if (message) {
|
|
47
|
+
this.span.status_message = message;
|
|
48
|
+
}
|
|
49
|
+
return this;
|
|
50
|
+
}
|
|
51
|
+
recordError(error) {
|
|
52
|
+
this.setStatus(types_1.SpanStatus.ERROR, error.message);
|
|
53
|
+
this.setAttributes({
|
|
54
|
+
'error.type': error.name,
|
|
55
|
+
'error.message': error.message,
|
|
56
|
+
'error.stack': error.stack,
|
|
57
|
+
});
|
|
58
|
+
this.addEvent('exception', {
|
|
59
|
+
'exception.type': error.name,
|
|
60
|
+
'exception.message': error.message,
|
|
61
|
+
});
|
|
62
|
+
return this;
|
|
63
|
+
}
|
|
64
|
+
end() {
|
|
65
|
+
this.span.end_time = new Date();
|
|
66
|
+
this.span.duration_ms = this.span.end_time.getTime() - this.span.start_time.getTime();
|
|
67
|
+
if (this.agent && typeof this.agent.reportSpan === 'function') {
|
|
68
|
+
this.agent.reportSpan(this.span);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
getSpan() {
|
|
72
|
+
return this.span;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
exports.SpanBuilder = SpanBuilder;
|
|
76
|
+
class TransactionBuilder extends SpanBuilder {
|
|
77
|
+
constructor(name, type, serviceName, serviceVersion, environment, sampled = true, agent) {
|
|
78
|
+
super(name, types_1.SpanKind.SERVER, serviceName, serviceVersion, environment, agent);
|
|
79
|
+
const span = this.getSpan();
|
|
80
|
+
this.transaction = {
|
|
81
|
+
...span,
|
|
82
|
+
transaction_type: type,
|
|
83
|
+
transaction_name: name,
|
|
84
|
+
sampled,
|
|
85
|
+
};
|
|
86
|
+
context_1.Context.setTransaction(this.transaction);
|
|
87
|
+
}
|
|
88
|
+
setResult(result) {
|
|
89
|
+
this.transaction.result = result;
|
|
90
|
+
return this;
|
|
91
|
+
}
|
|
92
|
+
end() {
|
|
93
|
+
this.transaction.end_time = new Date();
|
|
94
|
+
this.transaction.duration_ms =
|
|
95
|
+
this.transaction.end_time.getTime() - this.transaction.start_time.getTime();
|
|
96
|
+
if (this.agent && typeof this.agent.reportTransaction === 'function') {
|
|
97
|
+
this.agent.reportTransaction(this.transaction);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
getTransaction() {
|
|
101
|
+
return this.transaction;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
exports.TransactionBuilder = TransactionBuilder;
|
|
105
|
+
//# sourceMappingURL=span.js.map
|
package/dist/span.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"span.js","sourceRoot":"","sources":["../src/span.ts"],"names":[],"mappings":";;;AAAA,mCAA6E;AAC7E,uDAAuE;AACvE,6CAA0C;AAK1C,MAAa,WAAW;IAItB,YACE,IAAY,EACZ,IAAc,EACd,WAAmB,EACnB,cAAuB,EACvB,WAAoB,EACpB,KAAW;QAEX,MAAM,UAAU,GAAG,iBAAO,CAAC,cAAc,EAAE,CAAC;QAC5C,MAAM,OAAO,GAAG,iBAAO,CAAC,UAAU,EAAE,IAAI,IAAA,8BAAe,GAAE,CAAC;QAE1D,IAAI,CAAC,IAAI,GAAG;YACV,OAAO,EAAE,IAAA,6BAAc,GAAE;YACzB,QAAQ,EAAE,OAAO;YACjB,cAAc,EAAE,UAAU,EAAE,OAAO;YACnC,IAAI;YACJ,IAAI;YACJ,UAAU,EAAE,IAAI,IAAI,EAAE;YACtB,MAAM,EAAE,kBAAU,CAAC,EAAE;YACrB,UAAU,EAAE,EAAE;YACd,MAAM,EAAE,EAAE;YACV,YAAY,EAAE,WAAW;YACzB,eAAe,EAAE,cAAc;YAC/B,WAAW;SACZ,CAAC;QAEF,IAAI,CAAC,KAAK,GAAG,KAAK,CAAC;QAGnB,iBAAO,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC7B,CAAC;IAKD,YAAY,CAAC,GAAW,EAAE,KAAU;QAClC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;IAKD,aAAa,CAAC,UAA+B;QAC3C,MAAM,CAAC,MAA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AI,CAAC,WAAW,CAAC,CAAC;QAC1D,CAAC;IACH,CAAC;IAKD,cAAc;QACZ,OAAO,IAAI,CAAC,WAAW,CAAC;IAC1B,CAAC;CACF;AAtDD,gDAsDC"}
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
export interface AgentConfig {
|
|
2
|
+
serverUrl: string;
|
|
3
|
+
apiKey: string;
|
|
4
|
+
serviceName: string;
|
|
5
|
+
serviceVersion?: string;
|
|
6
|
+
environment?: string;
|
|
7
|
+
enabled?: boolean;
|
|
8
|
+
sampleRate?: number;
|
|
9
|
+
instrumentHttp?: boolean;
|
|
10
|
+
instrumentExpress?: boolean;
|
|
11
|
+
batchSize?: number;
|
|
12
|
+
flushInterval?: number;
|
|
13
|
+
debug?: boolean;
|
|
14
|
+
}
|
|
15
|
+
export declare enum SpanKind {
|
|
16
|
+
SERVER = "server",
|
|
17
|
+
CLIENT = "client",
|
|
18
|
+
INTERNAL = "internal",
|
|
19
|
+
PRODUCER = "producer",
|
|
20
|
+
CONSUMER = "consumer"
|
|
21
|
+
}
|
|
22
|
+
export declare enum SpanStatus {
|
|
23
|
+
OK = "ok",
|
|
24
|
+
ERROR = "error"
|
|
25
|
+
}
|
|
26
|
+
export interface Span {
|
|
27
|
+
span_id: string;
|
|
28
|
+
trace_id: string;
|
|
29
|
+
parent_span_id?: string;
|
|
30
|
+
name: string;
|
|
31
|
+
kind: SpanKind;
|
|
32
|
+
start_time: Date;
|
|
33
|
+
end_time?: Date;
|
|
34
|
+
duration_ms?: number;
|
|
35
|
+
status: SpanStatus;
|
|
36
|
+
status_message?: string;
|
|
37
|
+
attributes: Record<string, any>;
|
|
38
|
+
events: SpanEvent[];
|
|
39
|
+
service_name: string;
|
|
40
|
+
service_version?: string;
|
|
41
|
+
environment?: string;
|
|
42
|
+
}
|
|
43
|
+
export interface SpanEvent {
|
|
44
|
+
timestamp: Date;
|
|
45
|
+
name: string;
|
|
46
|
+
attributes?: Record<string, any>;
|
|
47
|
+
}
|
|
48
|
+
export interface Transaction extends Span {
|
|
49
|
+
transaction_type: string;
|
|
50
|
+
transaction_name: string;
|
|
51
|
+
result?: string;
|
|
52
|
+
sampled: boolean;
|
|
53
|
+
}
|
|
54
|
+
export interface LogEntry {
|
|
55
|
+
timestamp: Date;
|
|
56
|
+
level: string;
|
|
57
|
+
message: string;
|
|
58
|
+
trace_id?: string;
|
|
59
|
+
span_id?: string;
|
|
60
|
+
attributes?: Record<string, any>;
|
|
61
|
+
service_name: string;
|
|
62
|
+
environment?: string;
|
|
63
|
+
}
|
|
64
|
+
export interface ErrorData {
|
|
65
|
+
timestamp: Date;
|
|
66
|
+
message: string;
|
|
67
|
+
type: string;
|
|
68
|
+
stack_trace?: string;
|
|
69
|
+
trace_id?: string;
|
|
70
|
+
span_id?: string;
|
|
71
|
+
attributes?: Record<string, any>;
|
|
72
|
+
service_name: string;
|
|
73
|
+
environment?: string;
|
|
74
|
+
}
|
|
75
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAE1B,SAAS,EAAE,MAAM,CAAC;IAGlB,MAAM,EAAE,MAAM,CAAC;IAGf,WAAW,EAAE,MAAM,CAAC;IAGpB,cAAc,CAAC,EAAE,MAAM,CAAC;IAGxB,WAAW,CAAC,EAAE,MAAM,CAAC;IAGrB,OAAO,CAAC,EAAE,OAAO,CAAC;IAGlB,UAAU,CAAC,EAAE,MAAM,CAAC;IAGpB,cAAc,CAAC,EAAE,OAAO,CAAC;IAGzB,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAG5B,SAAS,CAAC,EAAE,MAAM,CAAC;IAGnB,aAAa,CAAC,EAAE,MAAM,CAAC;IAGvB,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAKD,oBAAY,QAAQ;IAClB,MAAM,WAAW;IACjB,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MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAKD,MAAM,WAAW,SAAS;IACxB,SAAS,EAAE,IAAI,CAAC;IAChB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IACjC,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB"}
|
package/dist/types.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.SpanStatus = exports.SpanKind = void 0;
|
|
4
|
+
var SpanKind;
|
|
5
|
+
(function (SpanKind) {
|
|
6
|
+
SpanKind["SERVER"] = "server";
|
|
7
|
+
SpanKind["CLIENT"] = "client";
|
|
8
|
+
SpanKind["INTERNAL"] = "internal";
|
|
9
|
+
SpanKind["PRODUCER"] = "producer";
|
|
10
|
+
SpanKind["CONSUMER"] = "consumer";
|
|
11
|
+
})(SpanKind || (exports.SpanKind = SpanKind = {}));
|
|
12
|
+
var SpanStatus;
|
|
13
|
+
(function (SpanStatus) {
|
|
14
|
+
SpanStatus["OK"] = "ok";
|
|
15
|
+
SpanStatus["ERROR"] = "error";
|
|
16
|
+
})(SpanStatus || (exports.SpanStatus = SpanStatus = {}));
|
|
17
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":";;;AA4CA,IAAY,QAMX;AAND,WAAY,QAAQ;IAClB,6BAAiB,CAAA;IACjB,6BAAiB,CAAA;IACjB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;IACrB,iCAAqB,CAAA;AACvB,CAAC,EANW,QAAQ,wBAAR,QAAQ,QAMnB;AAKD,IAAY,UAGX;AAHD,WAAY,UAAU;IACpB,uBAAS,CAAA;IACT,6BAAe,CAAA;AACjB,CAAC,EAHW,UAAU,0BAAV,UAAU,QAGrB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { Span, Transaction } from '../types';
|
|
2
|
+
interface ContextData {
|
|
3
|
+
transaction?: Transaction;
|
|
4
|
+
currentSpan?: Span;
|
|
5
|
+
traceId?: string;
|
|
6
|
+
spanId?: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class Context {
|
|
9
|
+
static run<T>(context: ContextData, fn: () => T): T;
|
|
10
|
+
static get(): ContextData | undefined;
|
|
11
|
+
static getCurrentTransaction(): Transaction | undefined;
|
|
12
|
+
static getCurrentSpan(): Span | undefined;
|
|
13
|
+
static getTraceId(): string | undefined;
|
|
14
|
+
static getSpanId(): string | undefined;
|
|
15
|
+
static setTransaction(transaction: Transaction): void;
|
|
16
|
+
static setSpan(span: Span): void;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=context.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAK7C,UAAU,WAAW;IACnB,WAAW,CAAC,EAAE,WAAW,CAAC;IAC1B,WAAW,CAAC,EAAE,IAAI,CAAC;IACnB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAUD,qBAAa,OAAO;IAIlB,MAAM,CAAC,GAAG,CAAC,CAAC,EAAE,OAAO,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC;IAOnD,MAAM,CAAC,GAAG,IAAI,WAAW,GAAG,SAAS;IAOrC,MAAM,CAAC,qBAAqB,IAAI,WAAW,GAAG,SAAS;IAOvD,MAAM,CAAC,cAAc,IAAI,IAAI,GAAG,SAAS;IAOzC,MAAM,CAAC,UAAU,IAAI,MAAM,GAAG,SAAS;IAOvC,MAAM,CAAC,SAAS,IAAI,MAAM,GAAG,SAAS;IAOtC,MAAM,CAAC,cAAc,CAAC,WAAW,EAAE,WAAW,GAAG,IAAI;IAYrD,MAAM,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,GAAG,IAAI;CAOjC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Context = void 0;
|
|
4
|
+
const async_hooks_1 = require("async_hooks");
|
|
5
|
+
const asyncLocalStorage = new async_hooks_1.AsyncLocalStorage();
|
|
6
|
+
class Context {
|
|
7
|
+
static run(context, fn) {
|
|
8
|
+
return asyncLocalStorage.run(context, fn);
|
|
9
|
+
}
|
|
10
|
+
static get() {
|
|
11
|
+
return asyncLocalStorage.getStore();
|
|
12
|
+
}
|
|
13
|
+
static getCurrentTransaction() {
|
|
14
|
+
return asyncLocalStorage.getStore()?.transaction;
|
|
15
|
+
}
|
|
16
|
+
static getCurrentSpan() {
|
|
17
|
+
return asyncLocalStorage.getStore()?.currentSpan;
|
|
18
|
+
}
|
|
19
|
+
static getTraceId() {
|
|
20
|
+
return asyncLocalStorage.getStore()?.traceId;
|
|
21
|
+
}
|
|
22
|
+
static getSpanId() {
|
|
23
|
+
return asyncLocalStorage.getStore()?.spanId;
|
|
24
|
+
}
|
|
25
|
+
static setTransaction(transaction) {
|
|
26
|
+
const store = asyncLocalStorage.getStore();
|
|
27
|
+
if (store) {
|
|
28
|
+
store.transaction = transaction;
|
|
29
|
+
store.traceId = transaction.trace_id;
|
|
30
|
+
store.spanId = transaction.span_id;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
static setSpan(span) {
|
|
34
|
+
const store = asyncLocalStorage.getStore();
|
|
35
|
+
if (store) {
|
|
36
|
+
store.currentSpan = span;
|
|
37
|
+
store.spanId = span.span_id;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
exports.Context = Context;
|
|
42
|
+
//# sourceMappingURL=context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context.js","sourceRoot":"","sources":["../../src/utils/context.ts"],"names":[],"mappings":";;;AAAA,6CAAgD;AAgBhD,MAAM,iBAAiB,GAAG,IAAI,+BAAiB,EAAe,CAAC;AAK/D,MAAa,OAAO;IAIlB,MAAM,CAAC,GAAG,CAAI,OAAoB,EAAE,EAAW;QAC7C,OAAO,iBAAiB,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;IAC5C,CAAC;IAKD,MAAM,CAAC,GAAG;QACR,OAAO,iBAAiB,CAAC,QAAQ,EAAE,CAAC;IACtC,CAAC;IAKD,MAAM,CAAC,qBAAqB;QAC1B,OAAO,iBAAiB,CAAC,QAAQ,EAAE,EAAE,WAAW,CAAC;IACnD,CAAC;IAKD,MAAM,CAAC,cAAc;QACnB,OAAO,iBAAiB,CAAC,QAAQ,EAAE,EAAE,WAAW,CAAC;IACnD,CAAC;IAKD,MAAM,CAAC,UAAU;QACf,OAAO,iBAAiB,CAAC,QAAQ,EAAE,EAAE,OAAO,CAAC;IAC/C,CAAC;IAKD,MAAM,CAAC,SAAS;QACd,OAAO,iBAAiB,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC;IAC9C,CAAC;IAKD,MAAM,CAAC,cAAc,CAAC,WAAwB;QAC5C,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,WAAW,GAAG,WAAW,CAAC;YAChC,KAAK,CAAC,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC;YACrC,KAAK,CAAC,MAAM,GAAG,WAAW,CAAC,OAAO,CAAC;QACrC,CAAC;IACH,CAAC;IAKD,MAAM,CAAC,OAAO,CAAC,IAAU;QACvB,MAAM,KAAK,GAAG,iBAAiB,CAAC,QAAQ,EAAE,CAAC;QAC3C,IAAI,KAAK,EAAE,CAAC;YACV,KAAK,CAAC,WAAW,GAAG,IAAI,CAAC;YACzB,KAAK,CAAC,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC;QAC9B,CAAC;IACH,CAAC;CACF;AAjED,0BAiEC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-generator.d.ts","sourceRoot":"","sources":["../../src/utils/id-generator.ts"],"names":[],"mappings":"AAKA,wBAAgB,eAAe,IAAI,MAAM,CAExC;AAKD,wBAAgB,cAAc,IAAI,MAAM,CAEvC;AAKD,wBAAgB,YAAY,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAExD"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.generateTraceId = generateTraceId;
|
|
4
|
+
exports.generateSpanId = generateSpanId;
|
|
5
|
+
exports.shouldSample = shouldSample;
|
|
6
|
+
const crypto_1 = require("crypto");
|
|
7
|
+
function generateTraceId() {
|
|
8
|
+
return (0, crypto_1.randomBytes)(16).toString('hex');
|
|
9
|
+
}
|
|
10
|
+
function generateSpanId() {
|
|
11
|
+
return (0, crypto_1.randomBytes)(8).toString('hex');
|
|
12
|
+
}
|
|
13
|
+
function shouldSample(sampleRate) {
|
|
14
|
+
return Math.random() < sampleRate;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=id-generator.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"id-generator.js","sourceRoot":"","sources":["../../src/utils/id-generator.ts"],"names":[],"mappings":";;AAKA,0CAEC;AAKD,wCAEC;AAKD,oCAEC;AArBD,mCAAqC;AAKrC,SAAgB,eAAe;IAC7B,OAAO,IAAA,oBAAW,EAAC,EAAE,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACzC,CAAC;AAKD,SAAgB,cAAc;IAC5B,OAAO,IAAA,oBAAW,EAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;AACxC,CAAC;AAKD,SAAgB,YAAY,CAAC,UAAkB;IAC7C,OAAO,IAAI,CAAC,MAAM,EAAE,GAAG,UAAU,CAAC;AACpC,CAAC"}
|