@avtechno/sfr 2.1.1 → 2.1.2
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/package.json
CHANGED
package/src/index.mts
CHANGED
|
@@ -9,23 +9,23 @@ import { trace } from "@opentelemetry/api";
|
|
|
9
9
|
|
|
10
10
|
// Define log levels matching standard syslog levels
|
|
11
11
|
const levels = {
|
|
12
|
-
error: 0,
|
|
13
|
-
warn: 1,
|
|
14
|
-
info: 2,
|
|
15
|
-
http: 3,
|
|
16
|
-
verbose: 4,
|
|
17
|
-
debug: 5,
|
|
18
|
-
silly: 6
|
|
12
|
+
error : 0,
|
|
13
|
+
warn : 1,
|
|
14
|
+
info : 2,
|
|
15
|
+
http : 3,
|
|
16
|
+
verbose : 4,
|
|
17
|
+
debug : 5,
|
|
18
|
+
silly : 6
|
|
19
19
|
};
|
|
20
20
|
|
|
21
21
|
const colors = {
|
|
22
|
-
error: "red",
|
|
23
|
-
warn: "yellow",
|
|
24
|
-
info: "green",
|
|
25
|
-
http: "magenta",
|
|
26
|
-
verbose: "cyan",
|
|
27
|
-
debug: "blue",
|
|
28
|
-
silly: "gray"
|
|
22
|
+
error : "red",
|
|
23
|
+
warn : "yellow",
|
|
24
|
+
info : "green",
|
|
25
|
+
http : "magenta",
|
|
26
|
+
verbose : "cyan",
|
|
27
|
+
debug : "blue",
|
|
28
|
+
silly : "gray"
|
|
29
29
|
};
|
|
30
30
|
|
|
31
31
|
winston.addColors(colors);
|
|
@@ -74,14 +74,10 @@ const pretty_format = winston.format.combine(
|
|
|
74
74
|
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss.SSS" }),
|
|
75
75
|
winston.format.colorize({ all: true }),
|
|
76
76
|
winston.format.printf((info) => {
|
|
77
|
-
const trace_suffix = info.trace_id
|
|
78
|
-
? ` [${String(info.trace_id).slice(0, 8)}]`
|
|
79
|
-
: "";
|
|
77
|
+
const trace_suffix = info.trace_id ? ` [${String(info.trace_id).slice(0, 8)}]` : "";
|
|
80
78
|
|
|
81
79
|
let meta_str = "";
|
|
82
|
-
const meta_keys = Object.keys(info).filter(
|
|
83
|
-
(k) => !["level", "message", "timestamp", "trace_id", "span_id", "trace_flags", "service"].includes(k)
|
|
84
|
-
);
|
|
80
|
+
const meta_keys = Object.keys(info).filter((k) => !["level", "message", "timestamp", "trace_id", "span_id", "trace_flags", "service"].includes(k));
|
|
85
81
|
|
|
86
82
|
if (meta_keys.length > 0) {
|
|
87
83
|
const meta_obj: Record<string, any> = {};
|
|
@@ -89,7 +85,7 @@ const pretty_format = winston.format.combine(
|
|
|
89
85
|
meta_str = ` ${JSON.stringify(meta_obj)}`;
|
|
90
86
|
}
|
|
91
87
|
|
|
92
|
-
return
|
|
88
|
+
return `[${info.timestamp}][${info.level}]${trace_suffix}: ${info.message} > ${meta_str}`;
|
|
93
89
|
})
|
|
94
90
|
);
|
|
95
91
|
|
|
@@ -150,13 +146,13 @@ export function create_child_logger(meta: Record<string, any>): winston.Logger {
|
|
|
150
146
|
* Automatically includes trace context when available.
|
|
151
147
|
*/
|
|
152
148
|
export const sfr_logger = {
|
|
153
|
-
error: (message: string, meta?: Record<string, any>) => get_logger().error(message, meta),
|
|
154
|
-
warn: (message: string, meta?: Record<string, any>) => get_logger().warn(message, meta),
|
|
155
|
-
info: (message: string, meta?: Record<string, any>) => get_logger().info(message, meta),
|
|
156
|
-
http: (message: string, meta?: Record<string, any>) => get_logger().http(message, meta),
|
|
157
|
-
verbose: (message: string, meta?: Record<string, any>) => get_logger().verbose(message, meta),
|
|
158
|
-
debug: (message: string, meta?: Record<string, any>) => get_logger().debug(message, meta),
|
|
159
|
-
silly: (message: string, meta?: Record<string, any>) => get_logger().silly(message, meta),
|
|
149
|
+
error : (message: string, meta?: Record<string, any>) => get_logger().error(message, meta),
|
|
150
|
+
warn : (message: string, meta?: Record<string, any>) => get_logger().warn(message, meta),
|
|
151
|
+
info : (message: string, meta?: Record<string, any>) => get_logger().info(message, meta),
|
|
152
|
+
http : (message: string, meta?: Record<string, any>) => get_logger().http(message, meta),
|
|
153
|
+
verbose : (message: string, meta?: Record<string, any>) => get_logger().verbose(message, meta),
|
|
154
|
+
debug : (message: string, meta?: Record<string, any>) => get_logger().debug(message, meta),
|
|
155
|
+
silly : (message: string, meta?: Record<string, any>) => get_logger().silly(message, meta),
|
|
160
156
|
|
|
161
157
|
/**
|
|
162
158
|
* Creates a child logger with additional context.
|
|
@@ -20,26 +20,26 @@ const METER_VERSION = "1.0.0";
|
|
|
20
20
|
*/
|
|
21
21
|
export interface SFRMetrics {
|
|
22
22
|
// REST Metrics
|
|
23
|
-
rest_requests_total: Counter;
|
|
24
|
-
rest_request_duration: Histogram;
|
|
25
|
-
rest_errors_total: Counter;
|
|
26
|
-
rest_request_size: Histogram;
|
|
27
|
-
rest_response_size: Histogram;
|
|
23
|
+
rest_requests_total : Counter;
|
|
24
|
+
rest_request_duration : Histogram;
|
|
25
|
+
rest_errors_total : Counter;
|
|
26
|
+
rest_request_size : Histogram;
|
|
27
|
+
rest_response_size : Histogram;
|
|
28
28
|
|
|
29
29
|
// WebSocket Metrics
|
|
30
|
-
ws_connections_active: UpDownCounter;
|
|
31
|
-
ws_connections_total: Counter;
|
|
32
|
-
ws_events_total: Counter;
|
|
33
|
-
ws_event_duration: Histogram;
|
|
34
|
-
ws_errors_total: Counter;
|
|
30
|
+
ws_connections_active : UpDownCounter;
|
|
31
|
+
ws_connections_total : Counter;
|
|
32
|
+
ws_events_total : Counter;
|
|
33
|
+
ws_event_duration : Histogram;
|
|
34
|
+
ws_errors_total : Counter;
|
|
35
35
|
|
|
36
36
|
// MQ Metrics
|
|
37
|
-
mq_messages_received: Counter;
|
|
38
|
-
mq_messages_published: Counter;
|
|
39
|
-
mq_processing_duration: Histogram;
|
|
40
|
-
mq_errors_total: Counter;
|
|
41
|
-
mq_messages_rejected: Counter;
|
|
42
|
-
mq_messages_acked: Counter;
|
|
37
|
+
mq_messages_received : Counter;
|
|
38
|
+
mq_messages_published : Counter;
|
|
39
|
+
mq_processing_duration : Histogram;
|
|
40
|
+
mq_errors_total : Counter;
|
|
41
|
+
mq_messages_rejected : Counter;
|
|
42
|
+
mq_messages_acked : Counter;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
let sfr_metrics: SFRMetrics | null = null;
|
|
@@ -53,9 +53,7 @@ export function wrap_mq_handler(
|
|
|
53
53
|
const ctx = trace.setSpan(parent_context, span);
|
|
54
54
|
|
|
55
55
|
// Record received metric
|
|
56
|
-
if (metrics) {
|
|
57
|
-
metrics.mq_messages_received.add(1, { queue, pattern });
|
|
58
|
-
}
|
|
56
|
+
if (metrics) metrics.mq_messages_received.add(1, { queue, pattern });
|
|
59
57
|
|
|
60
58
|
try {
|
|
61
59
|
await context.with(ctx, async () => {
|
|
@@ -48,7 +48,7 @@ export function sfr_rest_telemetry() {
|
|
|
48
48
|
"http.user_agent": req.get("user-agent") ?? "unknown",
|
|
49
49
|
"http.request_content_length": req.get("content-length") ?? 0,
|
|
50
50
|
"sfr.protocol": "REST",
|
|
51
|
-
"sfr.route": route
|
|
51
|
+
"sfr.route": route,
|
|
52
52
|
}
|
|
53
53
|
},
|
|
54
54
|
parent_context
|
package/src/sfr-pipeline.mts
CHANGED
|
@@ -88,6 +88,7 @@ export class SFRPipeline {
|
|
|
88
88
|
|
|
89
89
|
async init(base_url?: string): Promise<ServiceDocuments> {
|
|
90
90
|
this.base_url = base_url;
|
|
91
|
+
const observability_enabled = is_observability_enabled();
|
|
91
92
|
|
|
92
93
|
// Initialize observability with service config from oas_cfg
|
|
93
94
|
if (SFRPipeline.observability_options.enabled !== false) {
|
|
@@ -95,12 +96,12 @@ export class SFRPipeline {
|
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
// Add REST telemetry middleware if enabled
|
|
98
|
-
if (this.comms["REST"] &&
|
|
99
|
+
if (this.comms["REST"] && observability_enabled) {
|
|
99
100
|
this.comms["REST"].use(sfr_rest_telemetry());
|
|
100
101
|
}
|
|
101
102
|
|
|
102
103
|
// Instrument Socket.IO if enabled
|
|
103
|
-
if (this.comms["WS"] &&
|
|
104
|
+
if (this.comms["WS"] && observability_enabled) {
|
|
104
105
|
instrument_socket_io(this.comms["WS"]);
|
|
105
106
|
}
|
|
106
107
|
|