@loglayer/transport-victoria-logs 1.0.10 → 1.0.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/dist/index.cjs +78 -99
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -33
- package/dist/index.d.ts +36 -33
- package/dist/index.js +60 -78
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -1,109 +1,88 @@
|
|
|
1
|
-
|
|
1
|
+
//#region rolldown:runtime
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
8
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
17
|
};
|
|
18
|
-
var
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
19
22
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
VictoriaLogsTransport: () => VictoriaLogsTransport
|
|
24
|
-
});
|
|
25
|
-
module.exports = __toCommonJS(index_exports);
|
|
23
|
+
//#endregion
|
|
24
|
+
let __loglayer_transport_http = require("@loglayer/transport-http");
|
|
25
|
+
__loglayer_transport_http = __toESM(__loglayer_transport_http);
|
|
26
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
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
headers,
|
|
85
|
-
contentType,
|
|
86
|
-
batchContentType,
|
|
87
|
-
payloadTemplate,
|
|
88
|
-
compression,
|
|
89
|
-
maxRetries,
|
|
90
|
-
retryDelay,
|
|
91
|
-
respectRateLimit,
|
|
92
|
-
enableBatchSend,
|
|
93
|
-
batchSize,
|
|
94
|
-
batchSendTimeout,
|
|
95
|
-
batchSendDelimiter,
|
|
96
|
-
maxLogSize,
|
|
97
|
-
maxPayloadSize,
|
|
98
|
-
enableNextJsEdgeCompat,
|
|
99
|
-
onError,
|
|
100
|
-
onDebug,
|
|
101
|
-
...restConfig
|
|
102
|
-
});
|
|
103
|
-
}
|
|
27
|
+
//#region src/VictoriaLogsTransport.ts
|
|
28
|
+
/**
|
|
29
|
+
* VictoriaLogs transport for LogLayer.
|
|
30
|
+
*
|
|
31
|
+
* This transport is a thin wrapper around the HttpTransport that provides
|
|
32
|
+
* VictoriaLogs specific defaults and configuration. It uses the VictoriaLogs
|
|
33
|
+
* JSON stream API to send logs.
|
|
34
|
+
*
|
|
35
|
+
* @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
|
|
36
|
+
*/
|
|
37
|
+
var VictoriaLogsTransport = class extends __loglayer_transport_http.HttpTransport {
|
|
38
|
+
constructor(config = {}) {
|
|
39
|
+
const { url = "http://localhost:9428", method = "POST", headers = { "Content-Type": "application/stream+json" }, contentType = "application/stream+json", batchContentType = "application/stream+json", streamFields = () => ({}), timestamp = () => (/* @__PURE__ */ new Date()).toISOString(), httpParameters = {}, payloadTemplate = ({ logLevel, message, data }) => {
|
|
40
|
+
const streamFieldsData$1 = streamFields();
|
|
41
|
+
const timeValue = timestamp();
|
|
42
|
+
const msgField = httpParameters._msg_field || "_msg";
|
|
43
|
+
const timeField = httpParameters._time_field || "_time";
|
|
44
|
+
return JSON.stringify({
|
|
45
|
+
[msgField]: message || "(no message)",
|
|
46
|
+
[timeField]: timeValue,
|
|
47
|
+
level: logLevel,
|
|
48
|
+
...streamFieldsData$1,
|
|
49
|
+
...data
|
|
50
|
+
});
|
|
51
|
+
}, compression = false, maxRetries = 3, retryDelay = 1e3, respectRateLimit = true, enableBatchSend = true, batchSize = 100, batchSendTimeout = 5e3, batchSendDelimiter = "\n", maxLogSize = 1048576, maxPayloadSize = 5242880, enableNextJsEdgeCompat = false, onError, onDebug,...restConfig } = config;
|
|
52
|
+
const streamFieldsData = streamFields();
|
|
53
|
+
const streamFieldsKeys = Object.keys(streamFieldsData);
|
|
54
|
+
const finalHttpParameters = {
|
|
55
|
+
...httpParameters,
|
|
56
|
+
...streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(",") }
|
|
57
|
+
};
|
|
58
|
+
const baseUrl = `${url.replace(/\/$/, "")}/insert/jsonline`;
|
|
59
|
+
const queryParams = new URLSearchParams(finalHttpParameters);
|
|
60
|
+
const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl;
|
|
61
|
+
super({
|
|
62
|
+
url: fullUrl,
|
|
63
|
+
method,
|
|
64
|
+
headers,
|
|
65
|
+
contentType,
|
|
66
|
+
batchContentType,
|
|
67
|
+
payloadTemplate,
|
|
68
|
+
compression,
|
|
69
|
+
maxRetries,
|
|
70
|
+
retryDelay,
|
|
71
|
+
respectRateLimit,
|
|
72
|
+
enableBatchSend,
|
|
73
|
+
batchSize,
|
|
74
|
+
batchSendTimeout,
|
|
75
|
+
batchSendDelimiter,
|
|
76
|
+
maxLogSize,
|
|
77
|
+
maxPayloadSize,
|
|
78
|
+
enableNextJsEdgeCompat,
|
|
79
|
+
onError,
|
|
80
|
+
onDebug,
|
|
81
|
+
...restConfig
|
|
82
|
+
});
|
|
83
|
+
}
|
|
104
84
|
};
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
});
|
|
85
|
+
|
|
86
|
+
//#endregion
|
|
87
|
+
exports.VictoriaLogsTransport = VictoriaLogsTransport;
|
|
109
88
|
//# sourceMappingURL=index.cjs.map
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["HttpTransport","streamFieldsData"],"sources":["../src/VictoriaLogsTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the VictoriaLogs transport.\n * This is essentially a wrapper around HttpTransport with VictoriaLogs specific defaults.\n */\nexport interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"payloadTemplate\"> {\n /**\n * The VictoriaLogs host URL (e.g., http://localhost:9428)\n * The /insert/jsonline path will be automatically appended\n * @default \"http://localhost:9428\"\n */\n url?: string;\n /**\n * Function to transform log data into the payload format (optional, defaults to VictoriaLogs format)\n */\n payloadTemplate?: (data: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n /**\n * Function to generate stream-level fields for VictoriaLogs\n * The keys of the returned object will be used as the values for the _stream_fields parameter\n * @default () => ({})\n */\n streamFields?: () => Record<string, string>;\n /**\n * Function to generate the timestamp for the _time field\n * @default () => new Date().toISOString()\n */\n timestamp?: () => string;\n /**\n * Custom HTTP query parameters for VictoriaLogs ingestion\n * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#http-parameters\n */\n httpParameters?: Record<string, string>;\n}\n\n/**\n * VictoriaLogs transport for LogLayer.\n *\n * This transport is a thin wrapper around the HttpTransport that provides\n * VictoriaLogs specific defaults and configuration. It uses the VictoriaLogs\n * JSON stream API to send logs.\n *\n * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api\n */\nexport class VictoriaLogsTransport extends HttpTransport {\n constructor(config: VictoriaLogsTransportConfig = {}) {\n const {\n url = \"http://localhost:9428\",\n method = \"POST\",\n headers = {\n \"Content-Type\": \"application/stream+json\",\n },\n contentType = \"application/stream+json\",\n batchContentType = \"application/stream+json\",\n streamFields = () => ({}),\n timestamp = () => new Date().toISOString(),\n httpParameters = {},\n payloadTemplate = ({ logLevel, message, data }) => {\n const streamFieldsData = streamFields();\n const timeValue = timestamp();\n\n // Determine field names based on HTTP parameters\n const msgField = httpParameters._msg_field || \"_msg\";\n const timeField = httpParameters._time_field || \"_time\";\n\n return JSON.stringify({\n [msgField]: message || \"(no message)\",\n [timeField]: timeValue,\n level: logLevel,\n ...streamFieldsData,\n ...data,\n });\n },\n compression = false,\n maxRetries = 3,\n retryDelay = 1000,\n respectRateLimit = true,\n enableBatchSend = true,\n batchSize = 100,\n batchSendTimeout = 5000,\n batchSendDelimiter = \"\\n\",\n maxLogSize = 1048576, // 1MB\n maxPayloadSize = 5242880, // 5MB\n enableNextJsEdgeCompat = false,\n onError,\n onDebug,\n ...restConfig\n } = config;\n\n // Get stream fields and use their keys as _stream_fields parameter\n const streamFieldsData = streamFields();\n const streamFieldsKeys = Object.keys(streamFieldsData);\n\n // Merge HTTP parameters, adding _stream_fields if streamFields has keys\n const finalHttpParameters = {\n ...httpParameters,\n ...(streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(\",\") }),\n };\n\n // Construct the full URL with the VictoriaLogs JSON stream API endpoint and query parameters\n const baseUrl = `${url.replace(/\\/$/, \"\")}/insert/jsonline`;\n const queryParams = new URLSearchParams(finalHttpParameters);\n const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl;\n\n super({\n url: fullUrl,\n method,\n headers,\n contentType,\n batchContentType,\n payloadTemplate,\n compression,\n maxRetries,\n retryDelay,\n respectRateLimit,\n enableBatchSend,\n batchSize,\n batchSendTimeout,\n batchSendDelimiter,\n maxLogSize,\n maxPayloadSize,\n enableNextJsEdgeCompat,\n onError,\n onDebug,\n ...restConfig,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6CA,IAAa,wBAAb,cAA2CA,wCAAc;CACvD,YAAY,SAAsC,EAAE,EAAE;EACpD,MAAM,EACJ,MAAM,yBACN,SAAS,QACT,UAAU,EACR,gBAAgB,2BACjB,EACD,cAAc,2BACd,mBAAmB,2BACnB,sBAAsB,EAAE,GACxB,mCAAkB,IAAI,MAAM,EAAC,aAAa,EAC1C,iBAAiB,EAAE,EACnB,mBAAmB,EAAE,UAAU,SAAS,WAAW;GACjD,MAAMC,qBAAmB,cAAc;GACvC,MAAM,YAAY,WAAW;GAG7B,MAAM,WAAW,eAAe,cAAc;GAC9C,MAAM,YAAY,eAAe,eAAe;AAEhD,UAAO,KAAK,UAAU;KACnB,WAAW,WAAW;KACtB,YAAY;IACb,OAAO;IACP,GAAGA;IACH,GAAG;IACJ,CAAC;KAEJ,cAAc,OACd,aAAa,GACb,aAAa,KACb,mBAAmB,MACnB,kBAAkB,MAClB,YAAY,KACZ,mBAAmB,KACnB,qBAAqB,MACrB,aAAa,SACb,iBAAiB,SACjB,yBAAyB,OACzB,SACA,QACA,GAAG,eACD;EAGJ,MAAM,mBAAmB,cAAc;EACvC,MAAM,mBAAmB,OAAO,KAAK,iBAAiB;EAGtD,MAAM,sBAAsB;GAC1B,GAAG;GACH,GAAI,iBAAiB,SAAS,KAAK,EAAE,gBAAgB,iBAAiB,KAAK,IAAI,EAAE;GAClF;EAGD,MAAM,UAAU,GAAG,IAAI,QAAQ,OAAO,GAAG,CAAC;EAC1C,MAAM,cAAc,IAAI,gBAAgB,oBAAoB;EAC5D,MAAM,UAAU,YAAY,UAAU,GAAG,GAAG,QAAQ,GAAG,YAAY,UAAU,KAAK;AAElF,QAAM;GACJ,KAAK;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,GAAG;GACJ,CAAC"}
|
package/dist/index.d.cts
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpTransport, HttpTransportConfig } from "@loglayer/transport-http";
|
|
2
|
+
|
|
3
|
+
//#region src/VictoriaLogsTransport.d.ts
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Configuration options for the VictoriaLogs transport.
|
|
5
7
|
* This is essentially a wrapper around HttpTransport with VictoriaLogs specific defaults.
|
|
6
8
|
*/
|
|
7
9
|
interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, "url" | "payloadTemplate"> {
|
|
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
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The VictoriaLogs host URL (e.g., http://localhost:9428)
|
|
12
|
+
* The /insert/jsonline path will be automatically appended
|
|
13
|
+
* @default "http://localhost:9428"
|
|
14
|
+
*/
|
|
15
|
+
url?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Function to transform log data into the payload format (optional, defaults to VictoriaLogs format)
|
|
18
|
+
*/
|
|
19
|
+
payloadTemplate?: (data: {
|
|
20
|
+
logLevel: string;
|
|
21
|
+
message: string;
|
|
22
|
+
data?: Record<string, any>;
|
|
23
|
+
}) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Function to generate stream-level fields for VictoriaLogs
|
|
26
|
+
* The keys of the returned object will be used as the values for the _stream_fields parameter
|
|
27
|
+
* @default () => ({})
|
|
28
|
+
*/
|
|
29
|
+
streamFields?: () => Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Function to generate the timestamp for the _time field
|
|
32
|
+
* @default () => new Date().toISOString()
|
|
33
|
+
*/
|
|
34
|
+
timestamp?: () => string;
|
|
35
|
+
/**
|
|
36
|
+
* Custom HTTP query parameters for VictoriaLogs ingestion
|
|
37
|
+
* @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#http-parameters
|
|
38
|
+
*/
|
|
39
|
+
httpParameters?: Record<string, string>;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* VictoriaLogs transport for LogLayer.
|
|
@@ -46,7 +48,8 @@ interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, "url" |
|
|
|
46
48
|
* @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
|
|
47
49
|
*/
|
|
48
50
|
declare class VictoriaLogsTransport extends HttpTransport {
|
|
49
|
-
|
|
51
|
+
constructor(config?: VictoriaLogsTransportConfig);
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
//#endregion
|
|
52
54
|
export { VictoriaLogsTransport, type VictoriaLogsTransportConfig };
|
|
55
|
+
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,40 +1,42 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { HttpTransport, HttpTransportConfig } from "@loglayer/transport-http";
|
|
2
|
+
|
|
3
|
+
//#region src/VictoriaLogsTransport.d.ts
|
|
2
4
|
|
|
3
5
|
/**
|
|
4
6
|
* Configuration options for the VictoriaLogs transport.
|
|
5
7
|
* This is essentially a wrapper around HttpTransport with VictoriaLogs specific defaults.
|
|
6
8
|
*/
|
|
7
9
|
interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, "url" | "payloadTemplate"> {
|
|
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
|
-
|
|
10
|
+
/**
|
|
11
|
+
* The VictoriaLogs host URL (e.g., http://localhost:9428)
|
|
12
|
+
* The /insert/jsonline path will be automatically appended
|
|
13
|
+
* @default "http://localhost:9428"
|
|
14
|
+
*/
|
|
15
|
+
url?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Function to transform log data into the payload format (optional, defaults to VictoriaLogs format)
|
|
18
|
+
*/
|
|
19
|
+
payloadTemplate?: (data: {
|
|
20
|
+
logLevel: string;
|
|
21
|
+
message: string;
|
|
22
|
+
data?: Record<string, any>;
|
|
23
|
+
}) => string;
|
|
24
|
+
/**
|
|
25
|
+
* Function to generate stream-level fields for VictoriaLogs
|
|
26
|
+
* The keys of the returned object will be used as the values for the _stream_fields parameter
|
|
27
|
+
* @default () => ({})
|
|
28
|
+
*/
|
|
29
|
+
streamFields?: () => Record<string, string>;
|
|
30
|
+
/**
|
|
31
|
+
* Function to generate the timestamp for the _time field
|
|
32
|
+
* @default () => new Date().toISOString()
|
|
33
|
+
*/
|
|
34
|
+
timestamp?: () => string;
|
|
35
|
+
/**
|
|
36
|
+
* Custom HTTP query parameters for VictoriaLogs ingestion
|
|
37
|
+
* @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#http-parameters
|
|
38
|
+
*/
|
|
39
|
+
httpParameters?: Record<string, string>;
|
|
38
40
|
}
|
|
39
41
|
/**
|
|
40
42
|
* VictoriaLogs transport for LogLayer.
|
|
@@ -46,7 +48,8 @@ interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, "url" |
|
|
|
46
48
|
* @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
|
|
47
49
|
*/
|
|
48
50
|
declare class VictoriaLogsTransport extends HttpTransport {
|
|
49
|
-
|
|
51
|
+
constructor(config?: VictoriaLogsTransportConfig);
|
|
50
52
|
}
|
|
51
|
-
|
|
53
|
+
//#endregion
|
|
52
54
|
export { VictoriaLogsTransport, type VictoriaLogsTransportConfig };
|
|
55
|
+
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,82 +1,64 @@
|
|
|
1
|
-
// src/VictoriaLogsTransport.ts
|
|
2
1
|
import { HttpTransport } from "@loglayer/transport-http";
|
|
2
|
+
|
|
3
|
+
//#region src/VictoriaLogsTransport.ts
|
|
4
|
+
/**
|
|
5
|
+
* VictoriaLogs transport for LogLayer.
|
|
6
|
+
*
|
|
7
|
+
* This transport is a thin wrapper around the HttpTransport that provides
|
|
8
|
+
* VictoriaLogs specific defaults and configuration. It uses the VictoriaLogs
|
|
9
|
+
* JSON stream API to send logs.
|
|
10
|
+
*
|
|
11
|
+
* @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api
|
|
12
|
+
*/
|
|
3
13
|
var VictoriaLogsTransport = class extends HttpTransport {
|
|
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
|
-
...streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(",") }
|
|
51
|
-
};
|
|
52
|
-
const baseUrl = `${url.replace(/\/$/, "")}/insert/jsonline`;
|
|
53
|
-
const queryParams = new URLSearchParams(finalHttpParameters);
|
|
54
|
-
const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl;
|
|
55
|
-
super({
|
|
56
|
-
url: fullUrl,
|
|
57
|
-
method,
|
|
58
|
-
headers,
|
|
59
|
-
contentType,
|
|
60
|
-
batchContentType,
|
|
61
|
-
payloadTemplate,
|
|
62
|
-
compression,
|
|
63
|
-
maxRetries,
|
|
64
|
-
retryDelay,
|
|
65
|
-
respectRateLimit,
|
|
66
|
-
enableBatchSend,
|
|
67
|
-
batchSize,
|
|
68
|
-
batchSendTimeout,
|
|
69
|
-
batchSendDelimiter,
|
|
70
|
-
maxLogSize,
|
|
71
|
-
maxPayloadSize,
|
|
72
|
-
enableNextJsEdgeCompat,
|
|
73
|
-
onError,
|
|
74
|
-
onDebug,
|
|
75
|
-
...restConfig
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
export {
|
|
80
|
-
VictoriaLogsTransport
|
|
14
|
+
constructor(config = {}) {
|
|
15
|
+
const { url = "http://localhost:9428", method = "POST", headers = { "Content-Type": "application/stream+json" }, contentType = "application/stream+json", batchContentType = "application/stream+json", streamFields = () => ({}), timestamp = () => (/* @__PURE__ */ new Date()).toISOString(), httpParameters = {}, payloadTemplate = ({ logLevel, message, data }) => {
|
|
16
|
+
const streamFieldsData$1 = streamFields();
|
|
17
|
+
const timeValue = timestamp();
|
|
18
|
+
const msgField = httpParameters._msg_field || "_msg";
|
|
19
|
+
const timeField = httpParameters._time_field || "_time";
|
|
20
|
+
return JSON.stringify({
|
|
21
|
+
[msgField]: message || "(no message)",
|
|
22
|
+
[timeField]: timeValue,
|
|
23
|
+
level: logLevel,
|
|
24
|
+
...streamFieldsData$1,
|
|
25
|
+
...data
|
|
26
|
+
});
|
|
27
|
+
}, compression = false, maxRetries = 3, retryDelay = 1e3, respectRateLimit = true, enableBatchSend = true, batchSize = 100, batchSendTimeout = 5e3, batchSendDelimiter = "\n", maxLogSize = 1048576, maxPayloadSize = 5242880, enableNextJsEdgeCompat = false, onError, onDebug,...restConfig } = config;
|
|
28
|
+
const streamFieldsData = streamFields();
|
|
29
|
+
const streamFieldsKeys = Object.keys(streamFieldsData);
|
|
30
|
+
const finalHttpParameters = {
|
|
31
|
+
...httpParameters,
|
|
32
|
+
...streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(",") }
|
|
33
|
+
};
|
|
34
|
+
const baseUrl = `${url.replace(/\/$/, "")}/insert/jsonline`;
|
|
35
|
+
const queryParams = new URLSearchParams(finalHttpParameters);
|
|
36
|
+
const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl;
|
|
37
|
+
super({
|
|
38
|
+
url: fullUrl,
|
|
39
|
+
method,
|
|
40
|
+
headers,
|
|
41
|
+
contentType,
|
|
42
|
+
batchContentType,
|
|
43
|
+
payloadTemplate,
|
|
44
|
+
compression,
|
|
45
|
+
maxRetries,
|
|
46
|
+
retryDelay,
|
|
47
|
+
respectRateLimit,
|
|
48
|
+
enableBatchSend,
|
|
49
|
+
batchSize,
|
|
50
|
+
batchSendTimeout,
|
|
51
|
+
batchSendDelimiter,
|
|
52
|
+
maxLogSize,
|
|
53
|
+
maxPayloadSize,
|
|
54
|
+
enableNextJsEdgeCompat,
|
|
55
|
+
onError,
|
|
56
|
+
onDebug,
|
|
57
|
+
...restConfig
|
|
58
|
+
});
|
|
59
|
+
}
|
|
81
60
|
};
|
|
61
|
+
|
|
62
|
+
//#endregion
|
|
63
|
+
export { VictoriaLogsTransport };
|
|
82
64
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/VictoriaLogsTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the VictoriaLogs transport.\n * This is essentially a wrapper around HttpTransport with VictoriaLogs specific defaults.\n */\nexport interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"payloadTemplate\"> {\n /**\n * The VictoriaLogs host URL (e.g., http://localhost:9428)\n * The /insert/jsonline path will be automatically appended\n * @default \"http://localhost:9428\"\n */\n url?: string;\n /**\n * Function to transform log data into the payload format (optional, defaults to VictoriaLogs format)\n */\n payloadTemplate?: (data: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n /**\n * Function to generate stream-level fields for VictoriaLogs\n * The keys of the returned object will be used as the values for the _stream_fields parameter\n * @default () => ({})\n */\n streamFields?: () => Record<string, string>;\n /**\n * Function to generate the timestamp for the _time field\n * @default () => new Date().toISOString()\n */\n timestamp?: () => string;\n /**\n * Custom HTTP query parameters for VictoriaLogs ingestion\n * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#http-parameters\n */\n httpParameters?: Record<string, string>;\n}\n\n/**\n * VictoriaLogs transport for LogLayer.\n *\n * This transport is a thin wrapper around the HttpTransport that provides\n * VictoriaLogs specific defaults and configuration. It uses the VictoriaLogs\n * JSON stream API to send logs.\n *\n * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api\n */\nexport class VictoriaLogsTransport extends HttpTransport {\n constructor(config: VictoriaLogsTransportConfig = {}) {\n const {\n url = \"http://localhost:9428\",\n method = \"POST\",\n headers = {\n \"Content-Type\": \"application/stream+json\",\n },\n contentType = \"application/stream+json\",\n batchContentType = \"application/stream+json\",\n streamFields = () => ({}),\n timestamp = () => new Date().toISOString(),\n httpParameters = {},\n payloadTemplate = ({ logLevel, message, data }) => {\n const streamFieldsData = streamFields();\n const timeValue = timestamp();\n\n // Determine field names based on HTTP parameters\n const msgField = httpParameters._msg_field || \"_msg\";\n const timeField = httpParameters._time_field || \"_time\";\n\n return JSON.stringify({\n [msgField]: message || \"(no message)\",\n [timeField]: timeValue,\n level: logLevel,\n ...streamFieldsData,\n ...data,\n });\n },\n compression = false,\n maxRetries = 3,\n retryDelay = 1000,\n respectRateLimit = true,\n enableBatchSend = true,\n batchSize = 100,\n batchSendTimeout = 5000,\n batchSendDelimiter = \"\\n\",\n maxLogSize = 1048576, // 1MB\n maxPayloadSize = 5242880, // 5MB\n enableNextJsEdgeCompat = false,\n onError,\n onDebug,\n ...restConfig\n } = config;\n\n // Get stream fields and use their keys as _stream_fields parameter\n const streamFieldsData = streamFields();\n const streamFieldsKeys = Object.keys(streamFieldsData);\n\n // Merge HTTP parameters, adding _stream_fields if streamFields has keys\n const finalHttpParameters = {\n ...httpParameters,\n ...(streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(\",\") }),\n };\n\n // Construct the full URL with the VictoriaLogs JSON stream API endpoint and query parameters\n const baseUrl = `${url.replace(/\\/$/, \"\")}/insert/jsonline`;\n const queryParams = new URLSearchParams(finalHttpParameters);\n const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl;\n\n super({\n url: fullUrl,\n method,\n headers,\n contentType,\n batchContentType,\n payloadTemplate,\n compression,\n maxRetries,\n retryDelay,\n respectRateLimit,\n enableBatchSend,\n batchSize,\n batchSendTimeout,\n batchSendDelimiter,\n maxLogSize,\n maxPayloadSize,\n enableNextJsEdgeCompat,\n onError,\n onDebug,\n ...restConfig,\n });\n }\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":["streamFieldsData"],"sources":["../src/VictoriaLogsTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the VictoriaLogs transport.\n * This is essentially a wrapper around HttpTransport with VictoriaLogs specific defaults.\n */\nexport interface VictoriaLogsTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"payloadTemplate\"> {\n /**\n * The VictoriaLogs host URL (e.g., http://localhost:9428)\n * The /insert/jsonline path will be automatically appended\n * @default \"http://localhost:9428\"\n */\n url?: string;\n /**\n * Function to transform log data into the payload format (optional, defaults to VictoriaLogs format)\n */\n payloadTemplate?: (data: { logLevel: string; message: string; data?: Record<string, any> }) => string;\n /**\n * Function to generate stream-level fields for VictoriaLogs\n * The keys of the returned object will be used as the values for the _stream_fields parameter\n * @default () => ({})\n */\n streamFields?: () => Record<string, string>;\n /**\n * Function to generate the timestamp for the _time field\n * @default () => new Date().toISOString()\n */\n timestamp?: () => string;\n /**\n * Custom HTTP query parameters for VictoriaLogs ingestion\n * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#http-parameters\n */\n httpParameters?: Record<string, string>;\n}\n\n/**\n * VictoriaLogs transport for LogLayer.\n *\n * This transport is a thin wrapper around the HttpTransport that provides\n * VictoriaLogs specific defaults and configuration. It uses the VictoriaLogs\n * JSON stream API to send logs.\n *\n * @see https://docs.victoriametrics.com/victorialogs/data-ingestion/#json-stream-api\n */\nexport class VictoriaLogsTransport extends HttpTransport {\n constructor(config: VictoriaLogsTransportConfig = {}) {\n const {\n url = \"http://localhost:9428\",\n method = \"POST\",\n headers = {\n \"Content-Type\": \"application/stream+json\",\n },\n contentType = \"application/stream+json\",\n batchContentType = \"application/stream+json\",\n streamFields = () => ({}),\n timestamp = () => new Date().toISOString(),\n httpParameters = {},\n payloadTemplate = ({ logLevel, message, data }) => {\n const streamFieldsData = streamFields();\n const timeValue = timestamp();\n\n // Determine field names based on HTTP parameters\n const msgField = httpParameters._msg_field || \"_msg\";\n const timeField = httpParameters._time_field || \"_time\";\n\n return JSON.stringify({\n [msgField]: message || \"(no message)\",\n [timeField]: timeValue,\n level: logLevel,\n ...streamFieldsData,\n ...data,\n });\n },\n compression = false,\n maxRetries = 3,\n retryDelay = 1000,\n respectRateLimit = true,\n enableBatchSend = true,\n batchSize = 100,\n batchSendTimeout = 5000,\n batchSendDelimiter = \"\\n\",\n maxLogSize = 1048576, // 1MB\n maxPayloadSize = 5242880, // 5MB\n enableNextJsEdgeCompat = false,\n onError,\n onDebug,\n ...restConfig\n } = config;\n\n // Get stream fields and use their keys as _stream_fields parameter\n const streamFieldsData = streamFields();\n const streamFieldsKeys = Object.keys(streamFieldsData);\n\n // Merge HTTP parameters, adding _stream_fields if streamFields has keys\n const finalHttpParameters = {\n ...httpParameters,\n ...(streamFieldsKeys.length > 0 && { _stream_fields: streamFieldsKeys.join(\",\") }),\n };\n\n // Construct the full URL with the VictoriaLogs JSON stream API endpoint and query parameters\n const baseUrl = `${url.replace(/\\/$/, \"\")}/insert/jsonline`;\n const queryParams = new URLSearchParams(finalHttpParameters);\n const fullUrl = queryParams.toString() ? `${baseUrl}?${queryParams.toString()}` : baseUrl;\n\n super({\n url: fullUrl,\n method,\n headers,\n contentType,\n batchContentType,\n payloadTemplate,\n compression,\n maxRetries,\n retryDelay,\n respectRateLimit,\n enableBatchSend,\n batchSize,\n batchSendTimeout,\n batchSendDelimiter,\n maxLogSize,\n maxPayloadSize,\n enableNextJsEdgeCompat,\n onError,\n onDebug,\n ...restConfig,\n });\n }\n}\n"],"mappings":";;;;;;;;;;;;AA6CA,IAAa,wBAAb,cAA2C,cAAc;CACvD,YAAY,SAAsC,EAAE,EAAE;EACpD,MAAM,EACJ,MAAM,yBACN,SAAS,QACT,UAAU,EACR,gBAAgB,2BACjB,EACD,cAAc,2BACd,mBAAmB,2BACnB,sBAAsB,EAAE,GACxB,mCAAkB,IAAI,MAAM,EAAC,aAAa,EAC1C,iBAAiB,EAAE,EACnB,mBAAmB,EAAE,UAAU,SAAS,WAAW;GACjD,MAAMA,qBAAmB,cAAc;GACvC,MAAM,YAAY,WAAW;GAG7B,MAAM,WAAW,eAAe,cAAc;GAC9C,MAAM,YAAY,eAAe,eAAe;AAEhD,UAAO,KAAK,UAAU;KACnB,WAAW,WAAW;KACtB,YAAY;IACb,OAAO;IACP,GAAGA;IACH,GAAG;IACJ,CAAC;KAEJ,cAAc,OACd,aAAa,GACb,aAAa,KACb,mBAAmB,MACnB,kBAAkB,MAClB,YAAY,KACZ,mBAAmB,KACnB,qBAAqB,MACrB,aAAa,SACb,iBAAiB,SACjB,yBAAyB,OACzB,SACA,QACA,GAAG,eACD;EAGJ,MAAM,mBAAmB,cAAc;EACvC,MAAM,mBAAmB,OAAO,KAAK,iBAAiB;EAGtD,MAAM,sBAAsB;GAC1B,GAAG;GACH,GAAI,iBAAiB,SAAS,KAAK,EAAE,gBAAgB,iBAAiB,KAAK,IAAI,EAAE;GAClF;EAGD,MAAM,UAAU,GAAG,IAAI,QAAQ,OAAO,GAAG,CAAC;EAC1C,MAAM,cAAc,IAAI,gBAAgB,oBAAoB;EAC5D,MAAM,UAAU,YAAY,UAAU,GAAG,GAAG,QAAQ,GAAG,YAAY,UAAU,KAAK;AAElF,QAAM;GACJ,KAAK;GACL;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA;GACA,GAAG;GACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loglayer/transport-victoria-logs",
|
|
3
3
|
"description": "VictoriaLogs transport for the LogLayer logging library.",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.11",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"exports": {
|
|
@@ -28,19 +28,19 @@
|
|
|
28
28
|
"logs"
|
|
29
29
|
],
|
|
30
30
|
"dependencies": {
|
|
31
|
-
"@loglayer/transport-http": "1.1.
|
|
31
|
+
"@loglayer/transport-http": "1.1.2"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@types/node": "24.7.2",
|
|
34
35
|
"dotenv": "17.2.3",
|
|
35
|
-
"@types/node": "24.6.1",
|
|
36
36
|
"serialize-error": "12.0.0",
|
|
37
|
+
"tsdown": "0.15.7",
|
|
37
38
|
"tsx": "4.20.6",
|
|
38
|
-
"tsup": "8.5.0",
|
|
39
39
|
"typescript": "5.9.3",
|
|
40
40
|
"vitest": "3.2.4",
|
|
41
41
|
"@internal/tsconfig": "2.1.0",
|
|
42
|
-
"loglayer": "
|
|
43
|
-
"
|
|
42
|
+
"@loglayer/transport": "2.3.4",
|
|
43
|
+
"loglayer": "6.9.1"
|
|
44
44
|
},
|
|
45
45
|
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
46
46
|
"files": [
|
|
@@ -48,9 +48,9 @@
|
|
|
48
48
|
],
|
|
49
49
|
"homepage": "https://loglayer.dev/transports/victoria-logs",
|
|
50
50
|
"scripts": {
|
|
51
|
-
"build": "
|
|
51
|
+
"build": "tsdown src/index.ts",
|
|
52
52
|
"clean": "rm -rf .turbo node_modules dist",
|
|
53
|
-
"dev": "
|
|
53
|
+
"dev": "tsdown --watch",
|
|
54
54
|
"test": "vitest --run",
|
|
55
55
|
"test:watch": "vitest",
|
|
56
56
|
"lint": "biome check --no-errors-on-unmatched --write --unsafe src",
|