vtb-appit 0.1.9 → 0.1.11
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/appit-base-transformer.js +5 -3
- package/appit.js +70 -24
- package/package.json +7 -2
- package/tracing.js +26 -0
|
@@ -23,6 +23,11 @@ class AppitBaseTransformer {
|
|
|
23
23
|
return false;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
|
+
explores()
|
|
27
|
+
{
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
|
|
26
31
|
menu()
|
|
27
32
|
{
|
|
28
33
|
return false;
|
|
@@ -248,7 +253,6 @@ class AppitBaseTransformer {
|
|
|
248
253
|
|
|
249
254
|
r.on('end', () => {
|
|
250
255
|
let res = JSON.parse(data);
|
|
251
|
-
console.log('RES', res);
|
|
252
256
|
resolve(res);
|
|
253
257
|
});
|
|
254
258
|
});
|
|
@@ -283,7 +287,6 @@ class AppitBaseTransformer {
|
|
|
283
287
|
|
|
284
288
|
r.on('end', () => {
|
|
285
289
|
let res = JSON.parse(data);
|
|
286
|
-
console.log('RES', res);
|
|
287
290
|
resolve(res);
|
|
288
291
|
});
|
|
289
292
|
});
|
|
@@ -323,7 +326,6 @@ class AppitBaseTransformer {
|
|
|
323
326
|
});
|
|
324
327
|
|
|
325
328
|
res.on('end', () => {
|
|
326
|
-
console.log('JWT', JSON.parse(data).data.tsJWT.jwt);
|
|
327
329
|
resolve(JSON.parse(data).data.tsJWT.jwt);
|
|
328
330
|
});
|
|
329
331
|
});
|
package/appit.js
CHANGED
|
@@ -3,6 +3,35 @@ const pth = require("path");
|
|
|
3
3
|
const https = require('https');
|
|
4
4
|
const FormData = require('form-data');
|
|
5
5
|
const axios = require('axios');
|
|
6
|
+
require('./tracing');
|
|
7
|
+
const { trace, SpanStatusCode } = require('@opentelemetry/api');
|
|
8
|
+
|
|
9
|
+
const tracer = trace.getTracer('vtb-appit', '1.0.0');
|
|
10
|
+
//
|
|
11
|
+
// async function simulateWork() {
|
|
12
|
+
// return tracer.startActiveSpan('simulate-work', async (span) => {
|
|
13
|
+
// try {
|
|
14
|
+
// span.addEvent('Starting work simulation');
|
|
15
|
+
// span.setAttributes({
|
|
16
|
+
// 'work.type': 'simulation',
|
|
17
|
+
// 'work.duration': 1000
|
|
18
|
+
// });
|
|
19
|
+
//
|
|
20
|
+
// await new Promise(resolve => setTimeout(resolve, 1000));
|
|
21
|
+
//
|
|
22
|
+
// span.addEvent('Work simulation completed');
|
|
23
|
+
// span.setStatus({ code: SpanStatusCode.OK });
|
|
24
|
+
//
|
|
25
|
+
// return 'Work completed';
|
|
26
|
+
// } catch (error) {
|
|
27
|
+
// span.recordException(error);
|
|
28
|
+
// span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
29
|
+
// throw error;
|
|
30
|
+
// } finally {
|
|
31
|
+
// span.end();
|
|
32
|
+
// }
|
|
33
|
+
// });
|
|
34
|
+
// }
|
|
6
35
|
|
|
7
36
|
class Appit {
|
|
8
37
|
|
|
@@ -51,7 +80,6 @@ class Appit {
|
|
|
51
80
|
try {
|
|
52
81
|
const historyFile = fs.readFileSync(this.historyPath, {encoding: 'utf8'});
|
|
53
82
|
this.history = { ...defaultHistory, ...JSON.parse(historyFile) };
|
|
54
|
-
this.history.errors = [];
|
|
55
83
|
this.log('info', 'History loaded from file');
|
|
56
84
|
} catch(e) {
|
|
57
85
|
this.history = defaultHistory;
|
|
@@ -61,18 +89,50 @@ class Appit {
|
|
|
61
89
|
|
|
62
90
|
async exec()
|
|
63
91
|
{
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
92
|
+
this.log('info', 'Starting sync process');
|
|
93
|
+
const errors = [];
|
|
94
|
+
|
|
95
|
+
await tracer.startActiveSpan('appit-login', async (span) => {
|
|
67
96
|
try {
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
97
|
+
span.addEvent('Start login');
|
|
98
|
+
|
|
99
|
+
if(!await this.login()) {
|
|
100
|
+
this.log('info', 'Login failed');
|
|
101
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: 'Login failed' });
|
|
102
|
+
return false;
|
|
103
|
+
} else {
|
|
72
104
|
this.log('info', 'Login successful');
|
|
105
|
+
span.addEvent('Login successful');
|
|
106
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
107
|
+
}
|
|
108
|
+
} catch (error) {
|
|
109
|
+
span.recordException(error);
|
|
110
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
111
|
+
} finally{
|
|
112
|
+
span.end();
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if(!this.token) return;
|
|
73
117
|
|
|
74
|
-
|
|
75
|
-
|
|
118
|
+
await tracer.startActiveSpan('appit-profile', async (span) => {
|
|
119
|
+
try {
|
|
120
|
+
this.transformer.profile = await this.fetchProfile();
|
|
121
|
+
console.log(this.transformer.profile);
|
|
122
|
+
this.log('info', 'Profile fetched successfully');
|
|
123
|
+
|
|
124
|
+
span.addEvent('Profile fetched successfully');
|
|
125
|
+
span.setStatus({ code: SpanStatusCode.OK });
|
|
126
|
+
} catch(error) {
|
|
127
|
+
span.recordException(error);
|
|
128
|
+
span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
|
|
129
|
+
} finally {
|
|
130
|
+
span.end();
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+
try {
|
|
76
136
|
|
|
77
137
|
if(this.options && this.options.tsData) {
|
|
78
138
|
try {
|
|
@@ -97,7 +157,6 @@ class Appit {
|
|
|
97
157
|
const steps = [
|
|
98
158
|
{ name: 'excursion', fn: () => this.excursion() },
|
|
99
159
|
{ name: 'labels', fn: () => this.labels() },
|
|
100
|
-
{ name: 'explores', fn: () => this.explores() },
|
|
101
160
|
{ name: 'ships', fn: () => this.ships() },
|
|
102
161
|
{ name: 'places', fn: () => this.places() },
|
|
103
162
|
{ name: 'organizations', fn: () => this.organizations() },
|
|
@@ -194,14 +253,6 @@ class Appit {
|
|
|
194
253
|
}
|
|
195
254
|
}
|
|
196
255
|
|
|
197
|
-
async explores()
|
|
198
|
-
{
|
|
199
|
-
let explores = this.transformer.explores()
|
|
200
|
-
if(explores) {
|
|
201
|
-
await this.saveExplores(this.transformer.workspace_id, explores);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
|
|
205
256
|
async settings()
|
|
206
257
|
{
|
|
207
258
|
let settings = this.transformer.settings()
|
|
@@ -1741,11 +1792,6 @@ class Appit {
|
|
|
1741
1792
|
return await this.request('PUT', `workspaces/${workspace_id}/excursions/${this.history.excursionId}/settings`, data);
|
|
1742
1793
|
}
|
|
1743
1794
|
|
|
1744
|
-
async saveExplores(workspace_id, data)
|
|
1745
|
-
{
|
|
1746
|
-
return await this.request('POST', `workspaces/${workspace_id}/excursions/${this.history.excursionId}/explores`, data);
|
|
1747
|
-
}
|
|
1748
|
-
|
|
1749
1795
|
sleep(delay) {
|
|
1750
1796
|
return new Promise((resolve) => setTimeout(resolve, delay))
|
|
1751
1797
|
}
|
package/package.json
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vtb-appit",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.11",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {},
|
|
7
7
|
"author": "Chris Kanger",
|
|
8
8
|
"license": "ISC",
|
|
9
9
|
"dependencies": {
|
|
10
|
-
"axios": "^1.6.8"
|
|
10
|
+
"axios": "^1.6.8",
|
|
11
|
+
"@opentelemetry/api": "^1.9.0",
|
|
12
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.203.0",
|
|
13
|
+
"@opentelemetry/exporter-trace-otlp-http": "^0.203.0",
|
|
14
|
+
"@opentelemetry/instrumentation-http": "^0.203.0",
|
|
15
|
+
"@opentelemetry/sdk-node": "^0.203.0"
|
|
11
16
|
}
|
|
12
17
|
}
|
package/tracing.js
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const { NodeSDK } = require('@opentelemetry/sdk-node');
|
|
2
|
+
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
|
|
3
|
+
const { HttpInstrumentation } = require('@opentelemetry/instrumentation-http');
|
|
4
|
+
|
|
5
|
+
const traceExporter = new OTLPTraceExporter({
|
|
6
|
+
url: 'http://185.108.115.211:4318/v1/traces',
|
|
7
|
+
headers: {
|
|
8
|
+
'Content-Type': 'application/json',
|
|
9
|
+
},
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
// Add event listeners to monitor export status
|
|
13
|
+
traceExporter.on = traceExporter.on || (() => {});
|
|
14
|
+
|
|
15
|
+
console.log('Initializing OpenTelemetry with collector at: http://185.108.115.211:4318/v1/traces');
|
|
16
|
+
|
|
17
|
+
const sdk = new NodeSDK({
|
|
18
|
+
traceExporter,
|
|
19
|
+
instrumentations: [new HttpInstrumentation()]
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
sdk.start();
|
|
23
|
+
|
|
24
|
+
console.log('OpenTelemetry SDK started');
|
|
25
|
+
|
|
26
|
+
module.exports = sdk;
|