-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-server.js
More file actions
78 lines (63 loc) · 1.9 KB
/
test-server.js
File metadata and controls
78 lines (63 loc) · 1.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
/**
* Simple Node.js test to demonstrate FlowTrace with decorators
* This runs in Node.js so FlowTrace can instrument it
*/
const { Trace, TraceClass } = require('../../flowtrace-agent-js/src/decorators');
/**
* Test service with automatic tracing using decorators
*/
@TraceClass()
class TestService {
constructor() {
this.counter = 0;
}
increment() {
this.counter++;
console.log(`Counter incremented to: ${this.counter}`);
return this.counter;
}
@Trace({ methodName: 'process-data' })
processData(data) {
const result = data.map(item => item.toUpperCase());
console.log(`Processed ${result.length} items`);
return { processed: result.length, items: result };
}
delay(ms) {
return new Promise(resolve => setTimeout(resolve, ms));
}
async asyncOperation(value) {
console.log(`Starting async operation with value: ${value}`);
await this.delay(100);
const result = value * 2;
console.log(`Async operation completed: ${value} * 2 = ${result}`);
return result;
}
}
/**
* Main execution function
*/
async function main() {
console.log('=== FlowTrace Decorator Test ===\n');
const service = new TestService();
// Test 1: Simple method calls
console.log('Test 1: Increment counter');
service.increment();
service.increment();
service.increment();
console.log('\n');
// Test 2: Method with data processing
console.log('Test 2: Process data');
const data = ['hello', 'world', 'flowtrace', 'test'];
const result = service.processData(data);
console.log('Result:', result);
console.log('\n');
// Test 3: Async operations
console.log('Test 3: Async operations');
await service.asyncOperation(5);
await service.asyncOperation(10);
await service.asyncOperation(15);
console.log('\n=== Test completed ===');
console.log('✅ Check flowtrace.jsonl for execution logs');
}
// Run main function
main().catch(console.error);