-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenerator_logs.js
80 lines (62 loc) · 2.74 KB
/
generator_logs.js
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
79
80
const { hrTime, hrTimeToNanoseconds } = require('@opentelemetry/core');
const { Resource } = require('@opentelemetry/resources');
const { SemanticResourceAttributes,SemanticAttributes } = require('@opentelemetry/semantic-conventions');
const { faker } = require('@faker-js/faker');
// Simple implementation of the SDK Specification https://opentelemetry.io/docs/reference/specification/logs/logging-library-sdk/
// LogEmitterProvider, LogProcessor, LogEmitter are not demonstrated
// This is an oversimplifaction of what would be a exportable enum. For example SpanKind.SERVER
const LoggerSeverityText = {
TRACE: 'TRACE' ,
DEBUG: 'DEBUG',
INFO: 'INFO',
WARN : 'WARN',
ERROR: 'ERROR',
FATAL: 'FATAL'
};
const LoggerSeverityNumber = {
TRACE: 1,
TRACE2: 2,
DEBUG: 5,
DEBUG2: 6
}
// InstrumentationScope https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/#telemetry-sdk
// This is the equivalent of const logger = new LoggingProvider().getLogger('brisjs-sample-logs');
const BRISJS_LOGGER_INSTRUMENTATION_SCOPE ={
name : 'brisjs-sample-logs'
}
// Telemetry SDK Representation https://opentelemetry.io/docs/reference/specification/resource/semantic_conventions/#telemetry-sdk
const BRISJS_LOGGER_TELEMETRY_SDK ={
'telemetry.sdk.name' : 'brisjs-sample-logger',
'telemetry.sdk.language' : 'nodejs',
'telemetry.sdk.version' : '2022.4.1'
}
// This is the equivalent of const logger = new LoggingProvider(resource: = new Resource()).getLogger('brisjs-sample-logs');
const brisjs_logger_resource = new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'brisjs-otel-example',
[SemanticResourceAttributes.SERVICE_VERSION]: '0.0.1'
})
// simulates in a simple representation of what ConsoleMetricExporter or ConsoleSpanExporter do
function ConsoleLogExporter() {
const username = faker.internet.userName()
console.log(
JSON.stringify(
{
Timestamp: hrTimeToNanoseconds(hrTime()),
ObservedTimestamp: hrTimeToNanoseconds(hrTime()),
SeverityText: LoggerSeverityText.INFO,
Body: `A user with username: ${username} logged in from with IP ${faker.internet.ipv4()}`,
Resource: brisjs_logger_resource.attributes,
InstrumentationScope: BRISJS_LOGGER_INSTRUMENTATION_SCOPE,
Attributes: {
[SemanticAttributes.ENDUSER_ID]: username,
"brisjs.auth_strategy": "OIDC"
}
},null,4)
)
}
setInterval(() => {
const number_of_logs = parseInt(Math.random() * 10)
for (let i = 0; i < number_of_logs; i += 1) {
ConsoleLogExporter();
}
}, 5000);