@loglayer/transport-betterstack 1.0.0
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/LICENSE +21 -0
- package/README.md +46 -0
- package/dist/index.cjs +83 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +49 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +56 -0
- package/dist/index.js.map +1 -0
- package/package.json +66 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 LogLayer
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
# @loglayer/transport-betterstack
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@loglayer/transport-betterstack)
|
|
4
|
+
[](https://www.npmjs.com/package/@loglayer/transport-betterstack)
|
|
5
|
+
[](https://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
Better Stack transport for the LogLayer logging library. This transport sends logs to [Better Stack's log management platform](https://betterstack.com/log-management) using their HTTP API.
|
|
8
|
+
|
|
9
|
+
## Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
npm install @loglayer/transport-betterstack
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
yarn add @loglayer/transport-betterstack
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
pnpm add @loglayer/transport-betterstack
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
## Usage
|
|
24
|
+
|
|
25
|
+
- Create a "Javascript / Node.js" log source in your Better Stack account.
|
|
26
|
+
- In the "Data ingestion" tab of your source, find your `source token` and the `ingesting host`.
|
|
27
|
+
- Add `https://` in front of the ingesting host for the `url` parameter.
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
import { LogLayer } from "loglayer";
|
|
31
|
+
import { BetterStackTransport } from "@loglayer/transport-betterstack";
|
|
32
|
+
|
|
33
|
+
const transport = new BetterStackTransport({
|
|
34
|
+
sourceToken: "<source token>",
|
|
35
|
+
url: "https://<ingesting host>",
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const log = new LogLayer({ transport });
|
|
39
|
+
|
|
40
|
+
log.info("Hello, Better Stack!");
|
|
41
|
+
log.withMetadata({ userId: "123" }).info("User logged in");
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Configuration
|
|
45
|
+
|
|
46
|
+
For detailed configuration options and advanced usage, see the [Better Stack transport documentation](https://loglayer.dev/transports/betterstack).
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
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
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
BetterStackTransport: () => BetterStackTransport
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
26
|
+
|
|
27
|
+
// src/BetterStackTransport.ts
|
|
28
|
+
var import_transport_http = require("@loglayer/transport-http");
|
|
29
|
+
var BetterStackTransport = class extends import_transport_http.HttpTransport {
|
|
30
|
+
/**
|
|
31
|
+
* Creates a new instance of BetterStackTransport.
|
|
32
|
+
*
|
|
33
|
+
* @param config - Configuration options for the transport
|
|
34
|
+
*/
|
|
35
|
+
constructor(config) {
|
|
36
|
+
const url = config.url;
|
|
37
|
+
const includeTimestamp = config.includeTimestamp ?? true;
|
|
38
|
+
const timestampField = config.timestampField ?? "dt";
|
|
39
|
+
const httpConfig = {
|
|
40
|
+
...config,
|
|
41
|
+
url,
|
|
42
|
+
headers: {
|
|
43
|
+
Authorization: `Bearer ${config.sourceToken}`,
|
|
44
|
+
"Content-Type": "application/json"
|
|
45
|
+
},
|
|
46
|
+
payloadTemplate: (data) => {
|
|
47
|
+
const payload = {
|
|
48
|
+
message: data.message
|
|
49
|
+
};
|
|
50
|
+
if (data.logLevel) {
|
|
51
|
+
payload.level = data.logLevel;
|
|
52
|
+
}
|
|
53
|
+
if (data.data) {
|
|
54
|
+
Object.assign(payload, data.data);
|
|
55
|
+
}
|
|
56
|
+
if (includeTimestamp) {
|
|
57
|
+
payload[timestampField] = (/* @__PURE__ */ new Date()).toISOString();
|
|
58
|
+
}
|
|
59
|
+
return JSON.stringify(payload);
|
|
60
|
+
},
|
|
61
|
+
// Better Stack specific defaults
|
|
62
|
+
batchMode: "array",
|
|
63
|
+
batchContentType: "application/json",
|
|
64
|
+
enableBatchSend: config.enableBatchSend ?? true,
|
|
65
|
+
batchSize: config.batchSize ?? 100,
|
|
66
|
+
batchSendTimeout: config.batchSendTimeout ?? 5e3,
|
|
67
|
+
compression: config.compression ?? false,
|
|
68
|
+
maxRetries: config.maxRetries ?? 3,
|
|
69
|
+
retryDelay: config.retryDelay ?? 1e3,
|
|
70
|
+
respectRateLimit: config.respectRateLimit ?? true,
|
|
71
|
+
maxLogSize: config.maxLogSize ?? 1048576,
|
|
72
|
+
// 1MB
|
|
73
|
+
maxPayloadSize: config.maxPayloadSize ?? 10485760
|
|
74
|
+
// 10MB (Better Stack limit)
|
|
75
|
+
};
|
|
76
|
+
super(httpConfig);
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
80
|
+
0 && (module.exports = {
|
|
81
|
+
BetterStackTransport
|
|
82
|
+
});
|
|
83
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/BetterStackTransport.ts"],"sourcesContent":["export type { BetterStackTransportConfig } from \"./BetterStackTransport.js\";\nexport { BetterStackTransport } from \"./BetterStackTransport.js\";\n","import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the Better Stack transport.\n */\nexport interface BetterStackTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * Better Stack source token for authentication\n */\n sourceToken: string;\n /**\n * Better Stack ingestion host\n */\n url: string;\n /**\n * Whether to include timestamp in the log payload\n * @default true\n */\n includeTimestamp?: boolean;\n /**\n * Custom field name for the timestamp\n * @default \"dt\"\n */\n timestampField?: string;\n}\n\n/**\n * Better Stack transport for sending logs to Better Stack's log management platform.\n *\n * This transport extends the HTTP transport and configures it specifically for Better Stack's API.\n * It handles authentication, payload formatting, and batch sending according to Better Stack's requirements.\n *\n * Features:\n * - Automatic authentication with source token\n * - Proper payload formatting for Better Stack API\n * - Support for custom timestamps\n * - Batch sending with configurable size and timeout\n * - Error handling and retry logic\n * - Compression support\n */\nexport class BetterStackTransport extends HttpTransport {\n /**\n * Creates a new instance of BetterStackTransport.\n *\n * @param config - Configuration options for the transport\n */\n constructor(config: BetterStackTransportConfig) {\n const url = config.url;\n const includeTimestamp = config.includeTimestamp ?? true;\n const timestampField = config.timestampField ?? \"dt\";\n\n // Configure the HTTP transport with Better Stack specific settings\n const httpConfig: HttpTransportConfig = {\n ...config,\n url: url,\n headers: {\n Authorization: `Bearer ${config.sourceToken}`,\n \"Content-Type\": \"application/json\",\n },\n payloadTemplate: (data) => {\n const payload: Record<string, any> = {\n message: data.message,\n };\n\n // Add log level if available\n if (data.logLevel) {\n payload.level = data.logLevel;\n }\n\n // Add metadata if available\n if (data.data) {\n Object.assign(payload, data.data);\n }\n\n // Add timestamp if enabled\n if (includeTimestamp) {\n payload[timestampField] = new Date().toISOString();\n }\n\n return JSON.stringify(payload);\n },\n // Better Stack specific defaults\n batchMode: \"array\",\n batchContentType: \"application/json\",\n enableBatchSend: config.enableBatchSend ?? true,\n batchSize: config.batchSize ?? 100,\n batchSendTimeout: config.batchSendTimeout ?? 5000,\n compression: config.compression ?? false,\n maxRetries: config.maxRetries ?? 3,\n retryDelay: config.retryDelay ?? 1000,\n respectRateLimit: config.respectRateLimit ?? true,\n maxLogSize: config.maxLogSize ?? 1048576, // 1MB\n maxPayloadSize: config.maxPayloadSize ?? 10485760, // 10MB (Better Stack limit)\n };\n\n super(httpConfig);\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,4BAA8B;AAwCvB,IAAM,uBAAN,cAAmC,oCAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtD,YAAY,QAAoC;AAC9C,UAAM,MAAM,OAAO;AACnB,UAAM,mBAAmB,OAAO,oBAAoB;AACpD,UAAM,iBAAiB,OAAO,kBAAkB;AAGhD,UAAM,aAAkC;AAAA,MACtC,GAAG;AAAA,MACH;AAAA,MACA,SAAS;AAAA,QACP,eAAe,UAAU,OAAO,WAAW;AAAA,QAC3C,gBAAgB;AAAA,MAClB;AAAA,MACA,iBAAiB,CAAC,SAAS;AACzB,cAAM,UAA+B;AAAA,UACnC,SAAS,KAAK;AAAA,QAChB;AAGA,YAAI,KAAK,UAAU;AACjB,kBAAQ,QAAQ,KAAK;AAAA,QACvB;AAGA,YAAI,KAAK,MAAM;AACb,iBAAO,OAAO,SAAS,KAAK,IAAI;AAAA,QAClC;AAGA,YAAI,kBAAkB;AACpB,kBAAQ,cAAc,KAAI,oBAAI,KAAK,GAAE,YAAY;AAAA,QACnD;AAEA,eAAO,KAAK,UAAU,OAAO;AAAA,MAC/B;AAAA;AAAA,MAEA,WAAW;AAAA,MACX,kBAAkB;AAAA,MAClB,iBAAiB,OAAO,mBAAmB;AAAA,MAC3C,WAAW,OAAO,aAAa;AAAA,MAC/B,kBAAkB,OAAO,oBAAoB;AAAA,MAC7C,aAAa,OAAO,eAAe;AAAA,MACnC,YAAY,OAAO,cAAc;AAAA,MACjC,YAAY,OAAO,cAAc;AAAA,MACjC,kBAAkB,OAAO,oBAAoB;AAAA,MAC7C,YAAY,OAAO,cAAc;AAAA;AAAA,MACjC,gBAAgB,OAAO,kBAAkB;AAAA;AAAA,IAC3C;AAEA,UAAM,UAAU;AAAA,EAClB;AACF;","names":[]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HttpTransportConfig, HttpTransport } from '@loglayer/transport-http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Better Stack transport.
|
|
5
|
+
*/
|
|
6
|
+
interface BetterStackTransportConfig extends Omit<HttpTransportConfig, "url" | "headers" | "payloadTemplate"> {
|
|
7
|
+
/**
|
|
8
|
+
* Better Stack source token for authentication
|
|
9
|
+
*/
|
|
10
|
+
sourceToken: string;
|
|
11
|
+
/**
|
|
12
|
+
* Better Stack ingestion host
|
|
13
|
+
*/
|
|
14
|
+
url: string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to include timestamp in the log payload
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
includeTimestamp?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Custom field name for the timestamp
|
|
22
|
+
* @default "dt"
|
|
23
|
+
*/
|
|
24
|
+
timestampField?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Better Stack transport for sending logs to Better Stack's log management platform.
|
|
28
|
+
*
|
|
29
|
+
* This transport extends the HTTP transport and configures it specifically for Better Stack's API.
|
|
30
|
+
* It handles authentication, payload formatting, and batch sending according to Better Stack's requirements.
|
|
31
|
+
*
|
|
32
|
+
* Features:
|
|
33
|
+
* - Automatic authentication with source token
|
|
34
|
+
* - Proper payload formatting for Better Stack API
|
|
35
|
+
* - Support for custom timestamps
|
|
36
|
+
* - Batch sending with configurable size and timeout
|
|
37
|
+
* - Error handling and retry logic
|
|
38
|
+
* - Compression support
|
|
39
|
+
*/
|
|
40
|
+
declare class BetterStackTransport extends HttpTransport {
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new instance of BetterStackTransport.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Configuration options for the transport
|
|
45
|
+
*/
|
|
46
|
+
constructor(config: BetterStackTransportConfig);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { BetterStackTransport, type BetterStackTransportConfig };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { HttpTransportConfig, HttpTransport } from '@loglayer/transport-http';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Configuration options for the Better Stack transport.
|
|
5
|
+
*/
|
|
6
|
+
interface BetterStackTransportConfig extends Omit<HttpTransportConfig, "url" | "headers" | "payloadTemplate"> {
|
|
7
|
+
/**
|
|
8
|
+
* Better Stack source token for authentication
|
|
9
|
+
*/
|
|
10
|
+
sourceToken: string;
|
|
11
|
+
/**
|
|
12
|
+
* Better Stack ingestion host
|
|
13
|
+
*/
|
|
14
|
+
url: string;
|
|
15
|
+
/**
|
|
16
|
+
* Whether to include timestamp in the log payload
|
|
17
|
+
* @default true
|
|
18
|
+
*/
|
|
19
|
+
includeTimestamp?: boolean;
|
|
20
|
+
/**
|
|
21
|
+
* Custom field name for the timestamp
|
|
22
|
+
* @default "dt"
|
|
23
|
+
*/
|
|
24
|
+
timestampField?: string;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Better Stack transport for sending logs to Better Stack's log management platform.
|
|
28
|
+
*
|
|
29
|
+
* This transport extends the HTTP transport and configures it specifically for Better Stack's API.
|
|
30
|
+
* It handles authentication, payload formatting, and batch sending according to Better Stack's requirements.
|
|
31
|
+
*
|
|
32
|
+
* Features:
|
|
33
|
+
* - Automatic authentication with source token
|
|
34
|
+
* - Proper payload formatting for Better Stack API
|
|
35
|
+
* - Support for custom timestamps
|
|
36
|
+
* - Batch sending with configurable size and timeout
|
|
37
|
+
* - Error handling and retry logic
|
|
38
|
+
* - Compression support
|
|
39
|
+
*/
|
|
40
|
+
declare class BetterStackTransport extends HttpTransport {
|
|
41
|
+
/**
|
|
42
|
+
* Creates a new instance of BetterStackTransport.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Configuration options for the transport
|
|
45
|
+
*/
|
|
46
|
+
constructor(config: BetterStackTransportConfig);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export { BetterStackTransport, type BetterStackTransportConfig };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// src/BetterStackTransport.ts
|
|
2
|
+
import { HttpTransport } from "@loglayer/transport-http";
|
|
3
|
+
var BetterStackTransport = class extends HttpTransport {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new instance of BetterStackTransport.
|
|
6
|
+
*
|
|
7
|
+
* @param config - Configuration options for the transport
|
|
8
|
+
*/
|
|
9
|
+
constructor(config) {
|
|
10
|
+
const url = config.url;
|
|
11
|
+
const includeTimestamp = config.includeTimestamp ?? true;
|
|
12
|
+
const timestampField = config.timestampField ?? "dt";
|
|
13
|
+
const httpConfig = {
|
|
14
|
+
...config,
|
|
15
|
+
url,
|
|
16
|
+
headers: {
|
|
17
|
+
Authorization: `Bearer ${config.sourceToken}`,
|
|
18
|
+
"Content-Type": "application/json"
|
|
19
|
+
},
|
|
20
|
+
payloadTemplate: (data) => {
|
|
21
|
+
const payload = {
|
|
22
|
+
message: data.message
|
|
23
|
+
};
|
|
24
|
+
if (data.logLevel) {
|
|
25
|
+
payload.level = data.logLevel;
|
|
26
|
+
}
|
|
27
|
+
if (data.data) {
|
|
28
|
+
Object.assign(payload, data.data);
|
|
29
|
+
}
|
|
30
|
+
if (includeTimestamp) {
|
|
31
|
+
payload[timestampField] = (/* @__PURE__ */ new Date()).toISOString();
|
|
32
|
+
}
|
|
33
|
+
return JSON.stringify(payload);
|
|
34
|
+
},
|
|
35
|
+
// Better Stack specific defaults
|
|
36
|
+
batchMode: "array",
|
|
37
|
+
batchContentType: "application/json",
|
|
38
|
+
enableBatchSend: config.enableBatchSend ?? true,
|
|
39
|
+
batchSize: config.batchSize ?? 100,
|
|
40
|
+
batchSendTimeout: config.batchSendTimeout ?? 5e3,
|
|
41
|
+
compression: config.compression ?? false,
|
|
42
|
+
maxRetries: config.maxRetries ?? 3,
|
|
43
|
+
retryDelay: config.retryDelay ?? 1e3,
|
|
44
|
+
respectRateLimit: config.respectRateLimit ?? true,
|
|
45
|
+
maxLogSize: config.maxLogSize ?? 1048576,
|
|
46
|
+
// 1MB
|
|
47
|
+
maxPayloadSize: config.maxPayloadSize ?? 10485760
|
|
48
|
+
// 10MB (Better Stack limit)
|
|
49
|
+
};
|
|
50
|
+
super(httpConfig);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
BetterStackTransport
|
|
55
|
+
};
|
|
56
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/BetterStackTransport.ts"],"sourcesContent":["import type { HttpTransportConfig } from \"@loglayer/transport-http\";\nimport { HttpTransport } from \"@loglayer/transport-http\";\n\n/**\n * Configuration options for the Better Stack transport.\n */\nexport interface BetterStackTransportConfig extends Omit<HttpTransportConfig, \"url\" | \"headers\" | \"payloadTemplate\"> {\n /**\n * Better Stack source token for authentication\n */\n sourceToken: string;\n /**\n * Better Stack ingestion host\n */\n url: string;\n /**\n * Whether to include timestamp in the log payload\n * @default true\n */\n includeTimestamp?: boolean;\n /**\n * Custom field name for the timestamp\n * @default \"dt\"\n */\n timestampField?: string;\n}\n\n/**\n * Better Stack transport for sending logs to Better Stack's log management platform.\n *\n * This transport extends the HTTP transport and configures it specifically for Better Stack's API.\n * It handles authentication, payload formatting, and batch sending according to Better Stack's requirements.\n *\n * Features:\n * - Automatic authentication with source token\n * - Proper payload formatting for Better Stack API\n * - Support for custom timestamps\n * - Batch sending with configurable size and timeout\n * - Error handling and retry logic\n * - Compression support\n */\nexport class BetterStackTransport extends HttpTransport {\n /**\n * Creates a new instance of BetterStackTransport.\n *\n * @param config - Configuration options for the transport\n */\n constructor(config: BetterStackTransportConfig) {\n const url = config.url;\n const includeTimestamp = config.includeTimestamp ?? true;\n const timestampField = config.timestampField ?? \"dt\";\n\n // Configure the HTTP transport with Better Stack specific settings\n const httpConfig: HttpTransportConfig = {\n ...config,\n url: url,\n headers: {\n Authorization: `Bearer ${config.sourceToken}`,\n \"Content-Type\": \"application/json\",\n },\n payloadTemplate: (data) => {\n const payload: Record<string, any> = {\n message: data.message,\n };\n\n // Add log level if available\n if (data.logLevel) {\n payload.level = data.logLevel;\n }\n\n // Add metadata if available\n if (data.data) {\n Object.assign(payload, data.data);\n }\n\n // Add timestamp if enabled\n if (includeTimestamp) {\n payload[timestampField] = new Date().toISOString();\n }\n\n return JSON.stringify(payload);\n },\n // Better Stack specific defaults\n batchMode: \"array\",\n batchContentType: \"application/json\",\n enableBatchSend: config.enableBatchSend ?? true,\n batchSize: config.batchSize ?? 100,\n batchSendTimeout: config.batchSendTimeout ?? 5000,\n compression: config.compression ?? false,\n maxRetries: config.maxRetries ?? 3,\n retryDelay: config.retryDelay ?? 1000,\n respectRateLimit: config.respectRateLimit ?? true,\n maxLogSize: config.maxLogSize ?? 1048576, // 1MB\n maxPayloadSize: config.maxPayloadSize ?? 10485760, // 10MB (Better Stack limit)\n };\n\n super(httpConfig);\n }\n}\n"],"mappings":";AACA,SAAS,qBAAqB;AAwCvB,IAAM,uBAAN,cAAmC,cAAc;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAMtD,YAAY,QAAoC;AAC9C,UAAM,MAAM,OAAO;AACnB,UAAM,mBAAmB,OAAO,oBAAoB;AACpD,UAAM,iBAAiB,OAAO,kBAAkB;AAGhD,UAAM,aAAkC;AAAA,MACtC,GAAG;AAAA,MACH;AAAA,MACA,SAAS;AAAA,QACP,eAAe,UAAU,OAAO,WAAW;AAAA,QAC3C,gBAAgB;AAAA,MAClB;AAAA,MACA,iBAAiB,CAAC,SAAS;AACzB,cAAM,UAA+B;AAAA,UACnC,SAAS,KAAK;AAAA,QAChB;AAGA,YAAI,KAAK,UAAU;AACjB,kBAAQ,QAAQ,KAAK;AAAA,QACvB;AAGA,YAAI,KAAK,MAAM;AACb,iBAAO,OAAO,SAAS,KAAK,IAAI;AAAA,QAClC;AAGA,YAAI,kBAAkB;AACpB,kBAAQ,cAAc,KAAI,oBAAI,KAAK,GAAE,YAAY;AAAA,QACnD;AAEA,eAAO,KAAK,UAAU,OAAO;AAAA,MAC/B;AAAA;AAAA,MAEA,WAAW;AAAA,MACX,kBAAkB;AAAA,MAClB,iBAAiB,OAAO,mBAAmB;AAAA,MAC3C,WAAW,OAAO,aAAa;AAAA,MAC/B,kBAAkB,OAAO,oBAAoB;AAAA,MAC7C,aAAa,OAAO,eAAe;AAAA,MACnC,YAAY,OAAO,cAAc;AAAA,MACjC,YAAY,OAAO,cAAc;AAAA,MACjC,kBAAkB,OAAO,oBAAoB;AAAA,MAC7C,YAAY,OAAO,cAAc;AAAA;AAAA,MACjC,gBAAgB,OAAO,kBAAkB;AAAA;AAAA,IAC3C;AAEA,UAAM,UAAU;AAAA,EAClB;AACF;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loglayer/transport-betterstack",
|
|
3
|
+
"description": "Better Stack transport for the LogLayer logging library.",
|
|
4
|
+
"version": "1.0.0",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"exports": {
|
|
9
|
+
"import": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.js"
|
|
12
|
+
},
|
|
13
|
+
"require": {
|
|
14
|
+
"types": "./dist/index.d.cts",
|
|
15
|
+
"require": "./dist/index.cjs"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"types": "./dist/index.d.ts",
|
|
19
|
+
"license": "MIT",
|
|
20
|
+
"repository": {
|
|
21
|
+
"type": "git",
|
|
22
|
+
"url": "https://github.com/loglayer/loglayer.git",
|
|
23
|
+
"directory": "packages/transports/betterstack"
|
|
24
|
+
},
|
|
25
|
+
"author": "Theo Gravity <theo@suteki.nu>",
|
|
26
|
+
"keywords": [
|
|
27
|
+
"logging",
|
|
28
|
+
"log",
|
|
29
|
+
"loglayer",
|
|
30
|
+
"betterstack",
|
|
31
|
+
"transport",
|
|
32
|
+
"better stack"
|
|
33
|
+
],
|
|
34
|
+
"dependencies": {
|
|
35
|
+
"@loglayer/transport": "2.3.3",
|
|
36
|
+
"@loglayer/transport-http": "1.1.1"
|
|
37
|
+
},
|
|
38
|
+
"devDependencies": {
|
|
39
|
+
"dotenv": "17.2.3",
|
|
40
|
+
"@types/node": "24.6.1",
|
|
41
|
+
"serialize-error": "12.0.0",
|
|
42
|
+
"tsx": "4.20.6",
|
|
43
|
+
"tsup": "8.5.0",
|
|
44
|
+
"typescript": "5.9.3",
|
|
45
|
+
"vitest": "3.2.4",
|
|
46
|
+
"loglayer": "6.8.3",
|
|
47
|
+
"@internal/tsconfig": "2.1.0"
|
|
48
|
+
},
|
|
49
|
+
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
50
|
+
"engines": {
|
|
51
|
+
"node": ">=18"
|
|
52
|
+
},
|
|
53
|
+
"files": [
|
|
54
|
+
"dist"
|
|
55
|
+
],
|
|
56
|
+
"homepage": "https://loglayer.dev",
|
|
57
|
+
"scripts": {
|
|
58
|
+
"build": "tsup src/index.ts",
|
|
59
|
+
"test": "vitest --run",
|
|
60
|
+
"clean": "rm -rf .turbo node_modules dist",
|
|
61
|
+
"lint": "biome check --no-errors-on-unmatched --write --unsafe src",
|
|
62
|
+
"lint:staged": "biome check --no-errors-on-unmatched --write --unsafe --staged src",
|
|
63
|
+
"verify-types": "tsc --noEmit",
|
|
64
|
+
"livetest": "tsx src/__tests__/livetest.ts"
|
|
65
|
+
}
|
|
66
|
+
}
|