sloplog 0.0.8 → 0.0.10
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.
|
@@ -26,8 +26,6 @@ export interface SentryCollectorOptions {
|
|
|
26
26
|
level?: SentryLogLevel;
|
|
27
27
|
/** Optional function to derive log level per event */
|
|
28
28
|
levelSelector?: (event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions) => SentryLogLevel;
|
|
29
|
-
/** Log message to use (default: "wide-event") */
|
|
30
|
-
message?: string;
|
|
31
29
|
/**
|
|
32
30
|
* If true, flatten nested attributes to dot-notation keys for better
|
|
33
31
|
* queryability in Sentry (e.g., `error.message`, `spans.0.name`).
|
|
@@ -38,16 +36,16 @@ export interface SentryCollectorOptions {
|
|
|
38
36
|
/**
|
|
39
37
|
* Collector that sends events to Sentry Logs via the Sentry logger API.
|
|
40
38
|
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
39
|
+
* Generates a summary message with event ID, service name, and originator details.
|
|
40
|
+
* For HTTP originators, includes method and path.
|
|
41
|
+
*
|
|
42
|
+
* Attributes are flattened to dot-notation keys for better queryability
|
|
43
|
+
* in Sentry (e.g., `error.message`, `spans.0.name`).
|
|
45
44
|
*/
|
|
46
45
|
export declare class SentryCollector implements LogCollectorClient {
|
|
47
46
|
private getLogger;
|
|
48
47
|
private defaultLevel;
|
|
49
48
|
private levelSelector?;
|
|
50
|
-
private message;
|
|
51
49
|
private flattenAttributes;
|
|
52
50
|
constructor(options: SentryCollectorOptions);
|
|
53
51
|
flush(event: WideEventBase, partials: Map<string, PartialValue>, options: FlushOptions): Promise<void>;
|
|
@@ -1,17 +1,45 @@
|
|
|
1
1
|
import { flattenObject } from './index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Build a summary message for a wide event.
|
|
4
|
+
*
|
|
5
|
+
* Format: [WideEvent] eventId: {id} service: {serviceName} originator: {originatorType} {httpDetails}
|
|
6
|
+
*/
|
|
7
|
+
function buildSummaryMessage(event) {
|
|
8
|
+
const parts = ['[WideEvent]'];
|
|
9
|
+
// Event ID (shortened)
|
|
10
|
+
parts.push(`eventId:${event.eventId}`);
|
|
11
|
+
// Service name
|
|
12
|
+
if (event.service?.name) {
|
|
13
|
+
parts.push(`service:${event.service.name}`);
|
|
14
|
+
}
|
|
15
|
+
// Originator type and details
|
|
16
|
+
const originator = event.originator;
|
|
17
|
+
if (originator) {
|
|
18
|
+
parts.push(`originator:${originator.type}`);
|
|
19
|
+
// For HTTP originators, include method and path
|
|
20
|
+
if (originator.type === 'http') {
|
|
21
|
+
const method = originator.method;
|
|
22
|
+
const path = originator.path;
|
|
23
|
+
if (method && path) {
|
|
24
|
+
parts.push(`${method} ${path}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
return parts.join(' ');
|
|
29
|
+
}
|
|
2
30
|
/**
|
|
3
31
|
* Collector that sends events to Sentry Logs via the Sentry logger API.
|
|
4
32
|
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
33
|
+
* Generates a summary message with event ID, service name, and originator details.
|
|
34
|
+
* For HTTP originators, includes method and path.
|
|
35
|
+
*
|
|
36
|
+
* Attributes are flattened to dot-notation keys for better queryability
|
|
37
|
+
* in Sentry (e.g., `error.message`, `spans.0.name`).
|
|
9
38
|
*/
|
|
10
39
|
export class SentryCollector {
|
|
11
40
|
getLogger;
|
|
12
41
|
defaultLevel;
|
|
13
42
|
levelSelector;
|
|
14
|
-
message;
|
|
15
43
|
flattenAttributes;
|
|
16
44
|
constructor(options) {
|
|
17
45
|
// Support both direct logger and getter function for lazy initialization
|
|
@@ -19,7 +47,6 @@ export class SentryCollector {
|
|
|
19
47
|
typeof options.logger === 'function' ? options.logger : () => options.logger;
|
|
20
48
|
this.defaultLevel = options.level ?? 'info';
|
|
21
49
|
this.levelSelector = options.levelSelector;
|
|
22
|
-
this.message = options.message ?? 'wide-event';
|
|
23
50
|
this.flattenAttributes = options.flattenAttributes ?? true;
|
|
24
51
|
}
|
|
25
52
|
async flush(event, partials, options) {
|
|
@@ -42,6 +69,8 @@ export class SentryCollector {
|
|
|
42
69
|
const level = this.levelSelector
|
|
43
70
|
? this.levelSelector(event, partials, options)
|
|
44
71
|
: this.defaultLevel;
|
|
72
|
+
// Build summary message
|
|
73
|
+
const message = buildSummaryMessage(event);
|
|
45
74
|
const logFn = () => {
|
|
46
75
|
const loggerMethod = (level === 'trace' && logger.trace) ||
|
|
47
76
|
(level === 'debug' && logger.debug) ||
|
|
@@ -50,10 +79,10 @@ export class SentryCollector {
|
|
|
50
79
|
(level === 'error' && logger.error) ||
|
|
51
80
|
(level === 'fatal' && logger.fatal);
|
|
52
81
|
if (loggerMethod) {
|
|
53
|
-
loggerMethod(
|
|
82
|
+
loggerMethod(message, attributes);
|
|
54
83
|
return;
|
|
55
84
|
}
|
|
56
|
-
logger.log?.(level,
|
|
85
|
+
logger.log?.(level, message, attributes);
|
|
57
86
|
};
|
|
58
87
|
logFn();
|
|
59
88
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|