@loglayer/transport-datadog 1.0.1
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 +160 -0
- package/dist/index.cjs +41 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +37 -0
- package/dist/index.d.ts +37 -0
- package/dist/index.js +41 -0
- package/dist/index.js.map +1 -0
- package/package.json +59 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Theo Gravity
|
|
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,160 @@
|
|
|
1
|
+
# Datadog Transport for LogLayer
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/@loglayer/transport-datadog)
|
|
4
|
+
[](https://www.npmjs.com/package/@loglayer/transport-datadog)
|
|
5
|
+
[](http://www.typescriptlang.org/)
|
|
6
|
+
|
|
7
|
+
Ships logs to Datadog using the [datadog-transport-common](https://www.npmjs.com/package/datadog-transport-common) library.
|
|
8
|
+
|
|
9
|
+
## Important Notes
|
|
10
|
+
|
|
11
|
+
- Only works server-side (not in browsers)
|
|
12
|
+
* For browser-side logging, use the [`@loglayer/transport-datadog-browser-logs`](https://loglayer.dev/transports/datadog-browser-logs.html) package
|
|
13
|
+
- import `createDataDogTransport` from `@loglayer/transport-datadog` to create a new DataDog transport
|
|
14
|
+
- You will not get any console output since this sends directly to DataDog. Use the `onDebug` option to log out messages.
|
|
15
|
+
|
|
16
|
+
## Installation
|
|
17
|
+
|
|
18
|
+
```bash
|
|
19
|
+
npm install loglayer @loglayer/transport-datadog
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
```typescript
|
|
25
|
+
import { LogLayer } from 'loglayer'
|
|
26
|
+
import { createDataDogTransport } from "@loglayer/transport-datadog"
|
|
27
|
+
|
|
28
|
+
const log = new LogLayer({
|
|
29
|
+
transport: createDataDogTransport({
|
|
30
|
+
id: "datadog",
|
|
31
|
+
options: {
|
|
32
|
+
ddClientConf: {
|
|
33
|
+
authMethods: {
|
|
34
|
+
apiKeyAuth: "YOUR_API_KEY",
|
|
35
|
+
},
|
|
36
|
+
},
|
|
37
|
+
ddServerConf: {
|
|
38
|
+
// Note: This must match the site you use for your DataDog login - See below for more info
|
|
39
|
+
site: "datadoghq.eu"
|
|
40
|
+
},
|
|
41
|
+
onDebug: (msg) => {
|
|
42
|
+
console.log(msg);
|
|
43
|
+
},
|
|
44
|
+
onError: (err, logs) => {
|
|
45
|
+
console.error(err, logs);
|
|
46
|
+
},
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
})
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Configuration
|
|
53
|
+
|
|
54
|
+
```typescript
|
|
55
|
+
interface DataDogTransportOptions {
|
|
56
|
+
/**
|
|
57
|
+
* The ID of the transport.
|
|
58
|
+
*/
|
|
59
|
+
id?: string
|
|
60
|
+
/**
|
|
61
|
+
* Whether the transport is enabled. Default is true.
|
|
62
|
+
*/
|
|
63
|
+
enabled?: boolean
|
|
64
|
+
/**
|
|
65
|
+
* The field name to use for the message. Default is "message".
|
|
66
|
+
*/
|
|
67
|
+
messageField?: string;
|
|
68
|
+
/**
|
|
69
|
+
* The field name to use for the log level. Default is "level".
|
|
70
|
+
*/
|
|
71
|
+
levelField?: string;
|
|
72
|
+
/**
|
|
73
|
+
* The field name to use for the timestamp. Default is "time".
|
|
74
|
+
*/
|
|
75
|
+
timestampField?: string;
|
|
76
|
+
/**
|
|
77
|
+
* A custom function to stamp the timestamp. The default timestamp uses the ISO 8601 format.
|
|
78
|
+
*/
|
|
79
|
+
timestampFunction?: () => any;
|
|
80
|
+
/**
|
|
81
|
+
* The options for the transport.
|
|
82
|
+
*/
|
|
83
|
+
options: DDTransportOptions
|
|
84
|
+
}
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
```typescript
|
|
88
|
+
export interface DDTransportOptions {
|
|
89
|
+
/**
|
|
90
|
+
* DataDog client configuration parameters.
|
|
91
|
+
* @see https://datadoghq.dev/datadog-api-client-typescript/interfaces/client.Configuration.html
|
|
92
|
+
*/
|
|
93
|
+
ddClientConf: ConfigurationParameters
|
|
94
|
+
/**
|
|
95
|
+
* Datadog server config for the client. Use this to change the Datadog server region.
|
|
96
|
+
* @see https://github.com/DataDog/datadog-api-client-typescript/blob/1e1097c68a437894b482701ecbe3d61522429319/packages/datadog-api-client-common/servers.ts#L90
|
|
97
|
+
*/
|
|
98
|
+
ddServerConf?: {
|
|
99
|
+
/**
|
|
100
|
+
* The datadog server to use. Default is datadoghq.com.
|
|
101
|
+
* Other values could be:
|
|
102
|
+
* - us3.datadoghq.com
|
|
103
|
+
* - us5.datadoghq.com
|
|
104
|
+
* - datadoghq.eu
|
|
105
|
+
* - ddog-gov.com
|
|
106
|
+
*/
|
|
107
|
+
site?: string
|
|
108
|
+
subdomain?: string
|
|
109
|
+
protocol?: string
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* The integration name associated with your log: the technology from which
|
|
113
|
+
* the log originated. When it matches an integration name, Datadog
|
|
114
|
+
* automatically installs the corresponding parsers and facets.
|
|
115
|
+
* @see https://docs.datadoghq.com/logs/log_collection/?tab=host#reserved-attributes
|
|
116
|
+
*/
|
|
117
|
+
ddsource?: string
|
|
118
|
+
/**
|
|
119
|
+
* Comma separated tags associated with your logs. Ex: "env:prod,org:finance"
|
|
120
|
+
*/
|
|
121
|
+
ddtags?: string
|
|
122
|
+
/**
|
|
123
|
+
* The name of the application or service generating the log events.
|
|
124
|
+
* Default is "Electron"
|
|
125
|
+
* @see https://docs.datadoghq.com/logs/log_collection/?tab=host#reserved-attributes
|
|
126
|
+
*/
|
|
127
|
+
service?: string
|
|
128
|
+
/**
|
|
129
|
+
* Called when the plugin is ready to process logs.
|
|
130
|
+
*/
|
|
131
|
+
onInit?: () => void
|
|
132
|
+
/**
|
|
133
|
+
* Error handler for when the submitLog() call fails.
|
|
134
|
+
*/
|
|
135
|
+
onError?: (err: any, logs?: Array<Record<string, any>>) => void
|
|
136
|
+
/**
|
|
137
|
+
* Define this callback to get debug messages from this transport
|
|
138
|
+
*/
|
|
139
|
+
onDebug?: (msg: string) => void
|
|
140
|
+
/**
|
|
141
|
+
* Number of times to retry sending the log before onError() is called.
|
|
142
|
+
* Default is 5.
|
|
143
|
+
*/
|
|
144
|
+
retries?: number
|
|
145
|
+
/**
|
|
146
|
+
* Interval in which logs are sent to Datadog.
|
|
147
|
+
* Default is 3000 milliseconds.
|
|
148
|
+
*/
|
|
149
|
+
sendIntervalMs?: number
|
|
150
|
+
/**
|
|
151
|
+
* Set to true to disable batch sending and send each log as it comes in. This disables
|
|
152
|
+
* the send interval.
|
|
153
|
+
*/
|
|
154
|
+
sendImmediate?: boolean
|
|
155
|
+
}
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
## Documentation
|
|
159
|
+
|
|
160
|
+
For more details, visit [https://loglayer.dev/transports/datadog](https://loglayer.dev/transports/datadog)
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/DataDogTransport.ts
|
|
2
|
+
var _transport = require('@loglayer/transport');
|
|
3
|
+
var _datadogtransportcommon = require('datadog-transport-common');
|
|
4
|
+
var DataDogTransport = class extends _transport.BaseTransport {
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.messageField = _nullishCoalesce(config.messageField, () => ( "message"));
|
|
12
|
+
this.levelField = _nullishCoalesce(config.levelField, () => ( "level"));
|
|
13
|
+
this.timestampField = _nullishCoalesce(config.timestampField, () => ( "time"));
|
|
14
|
+
this.timestampFunction = config.timestampFunction;
|
|
15
|
+
}
|
|
16
|
+
shipToLogger({ logLevel, messages, data, hasData }) {
|
|
17
|
+
const logEntry = {};
|
|
18
|
+
if (data && hasData) {
|
|
19
|
+
Object.assign(logEntry, data);
|
|
20
|
+
}
|
|
21
|
+
if (this.timestampField && this.timestampFunction) {
|
|
22
|
+
logEntry[this.timestampField] = this.timestampFunction();
|
|
23
|
+
} else {
|
|
24
|
+
logEntry[this.timestampField] = (/* @__PURE__ */ new Date()).toISOString();
|
|
25
|
+
}
|
|
26
|
+
logEntry[this.levelField] = logLevel;
|
|
27
|
+
logEntry[this.messageField] = messages.join(" ");
|
|
28
|
+
this.logger.processLog(logEntry);
|
|
29
|
+
return messages;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function createDataDogTransport(config) {
|
|
33
|
+
return new DataDogTransport({
|
|
34
|
+
...config,
|
|
35
|
+
logger: new (0, _datadogtransportcommon.DataDogTransport)(config.options)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
exports.createDataDogTransport = createDataDogTransport;
|
|
41
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/loglayer/loglayer/packages/transports/datadog/dist/index.cjs","../src/DataDogTransport.ts"],"names":[],"mappings":"AAAA;ACAA,gDAA4D;AAE5D,kEAAoF;AAyBpF,IAAM,iBAAA,EAAN,MAAA,QAA+B,yBAAsC;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,WAAA,CAAY,MAAA,EAAkG;AAC5G,IAAA,KAAA,CAAM,MAAM,CAAA;AAEZ,IAAA,IAAA,CAAK,aAAA,mBAAe,MAAA,CAAO,YAAA,UAAgB,WAAA;AAC3C,IAAA,IAAA,CAAK,WAAA,mBAAa,MAAA,CAAO,UAAA,UAAc,SAAA;AACvC,IAAA,IAAA,CAAK,eAAA,mBAAiB,MAAA,CAAO,cAAA,UAAkB,QAAA;AAC/C,IAAA,IAAA,CAAK,kBAAA,EAAoB,MAAA,CAAO,iBAAA;AAAA,EAClC;AAAA,EAEA,YAAA,CAAa,EAAE,QAAA,EAAU,QAAA,EAAU,IAAA,EAAM,QAAQ,CAAA,EAA4B;AAC3E,IAAA,MAAM,SAAA,EAAgC,CAAC,CAAA;AAEvC,IAAA,GAAA,CAAI,KAAA,GAAQ,OAAA,EAAS;AACnB,MAAA,MAAA,CAAO,MAAA,CAAO,QAAA,EAAU,IAAI,CAAA;AAAA,IAC9B;AAEA,IAAA,GAAA,CAAI,IAAA,CAAK,eAAA,GAAkB,IAAA,CAAK,iBAAA,EAAmB;AACjD,MAAA,QAAA,CAAS,IAAA,CAAK,cAAc,EAAA,EAAI,IAAA,CAAK,iBAAA,CAAkB,CAAA;AAAA,IACzD,EAAA,KAAO;AACL,MAAA,QAAA,CAAS,IAAA,CAAK,cAAc,EAAA,EAAA,iBAAI,IAAI,IAAA,CAAK,CAAA,CAAA,CAAE,WAAA,CAAY,CAAA;AAAA,IACzD;AAEA,IAAA,QAAA,CAAS,IAAA,CAAK,UAAU,EAAA,EAAI,QAAA;AAC5B,IAAA,QAAA,CAAS,IAAA,CAAK,YAAY,EAAA,EAAI,QAAA,CAAS,IAAA,CAAK,GAAG,CAAA;AAE/C,IAAA,IAAA,CAAK,MAAA,CAAO,UAAA,CAAW,QAAQ,CAAA;AAE/B,IAAA,OAAO,QAAA;AAAA,EACT;AACF,CAAA;AAEO,SAAS,sBAAA,CAAuB,MAAA,EAAgC;AACrE,EAAA,OAAO,IAAI,gBAAA,CAAiB;AAAA,IAC1B,GAAG,MAAA;AAAA,IACH,MAAA,EAAQ,IAAI,6CAAA,CAAuB,MAAA,CAAO,OAAO;AAAA,EACnD,CAAC,CAAA;AACH;ADhCA;AACE;AACF,wDAAC","file":"/home/runner/work/loglayer/loglayer/packages/transports/datadog/dist/index.cjs","sourcesContent":[null,"import { BaseTransport, type LogLayerTransportParams } from \"@loglayer/transport\";\nimport type { LogLayerTransportConfig } from \"@loglayer/transport\";\nimport { type DDTransportOptions, DataDogTransport as DatadogTransportCommon } from \"datadog-transport-common\";\n\nexport interface DatadogTransportConfig extends Omit<LogLayerTransportConfig<DatadogTransportCommon>, \"logger\"> {\n /**\n * The options to pass to the datadog-transport-common instance.\n */\n options: DDTransportOptions;\n /**\n * The field name to use for the message. Default is \"message\".\n */\n messageField?: string;\n /**\n * The field name to use for the log level. Default is \"level\".\n */\n levelField?: string;\n /**\n * The field name to use for the timestamp. Default is \"time\".\n */\n timestampField?: string;\n /**\n * A custom function to stamp the timestamp\n */\n timestampFunction?: () => any;\n}\n\nclass DataDogTransport extends BaseTransport<DatadogTransportCommon> {\n messageField: string;\n levelField: string;\n timestampField: string;\n timestampFunction?: () => any;\n\n constructor(config: DatadogTransportConfig & Pick<LogLayerTransportConfig<DatadogTransportCommon>, \"logger\">) {\n super(config);\n\n this.messageField = config.messageField ?? \"message\";\n this.levelField = config.levelField ?? \"level\";\n this.timestampField = config.timestampField ?? \"time\";\n this.timestampFunction = config.timestampFunction;\n }\n\n shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams) {\n const logEntry: Record<string, any> = {};\n\n if (data && hasData) {\n Object.assign(logEntry, data);\n }\n\n if (this.timestampField && this.timestampFunction) {\n logEntry[this.timestampField] = this.timestampFunction();\n } else {\n logEntry[this.timestampField] = new Date().toISOString();\n }\n\n logEntry[this.levelField] = logLevel;\n logEntry[this.messageField] = messages.join(\" \");\n\n this.logger.processLog(logEntry);\n\n return messages;\n }\n}\n\nexport function createDataDogTransport(config: DatadogTransportConfig) {\n return new DataDogTransport({\n ...config,\n logger: new DatadogTransportCommon(config.options),\n });\n}\n"]}
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LogLayerTransportConfig, BaseTransport, LogLayerTransportParams } from '@loglayer/transport';
|
|
2
|
+
import { DataDogTransport as DataDogTransport$1, DDTransportOptions } from 'datadog-transport-common';
|
|
3
|
+
export { DDTransportOptions } from 'datadog-transport-common';
|
|
4
|
+
|
|
5
|
+
interface DatadogTransportConfig extends Omit<LogLayerTransportConfig<DataDogTransport$1>, "logger"> {
|
|
6
|
+
/**
|
|
7
|
+
* The options to pass to the datadog-transport-common instance.
|
|
8
|
+
*/
|
|
9
|
+
options: DDTransportOptions;
|
|
10
|
+
/**
|
|
11
|
+
* The field name to use for the message. Default is "message".
|
|
12
|
+
*/
|
|
13
|
+
messageField?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The field name to use for the log level. Default is "level".
|
|
16
|
+
*/
|
|
17
|
+
levelField?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The field name to use for the timestamp. Default is "time".
|
|
20
|
+
*/
|
|
21
|
+
timestampField?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A custom function to stamp the timestamp
|
|
24
|
+
*/
|
|
25
|
+
timestampFunction?: () => any;
|
|
26
|
+
}
|
|
27
|
+
declare class DataDogTransport extends BaseTransport<DataDogTransport$1> {
|
|
28
|
+
messageField: string;
|
|
29
|
+
levelField: string;
|
|
30
|
+
timestampField: string;
|
|
31
|
+
timestampFunction?: () => any;
|
|
32
|
+
constructor(config: DatadogTransportConfig & Pick<LogLayerTransportConfig<DataDogTransport$1>, "logger">);
|
|
33
|
+
shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams): any[];
|
|
34
|
+
}
|
|
35
|
+
declare function createDataDogTransport(config: DatadogTransportConfig): DataDogTransport;
|
|
36
|
+
|
|
37
|
+
export { type DatadogTransportConfig, createDataDogTransport };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { LogLayerTransportConfig, BaseTransport, LogLayerTransportParams } from '@loglayer/transport';
|
|
2
|
+
import { DataDogTransport as DataDogTransport$1, DDTransportOptions } from 'datadog-transport-common';
|
|
3
|
+
export { DDTransportOptions } from 'datadog-transport-common';
|
|
4
|
+
|
|
5
|
+
interface DatadogTransportConfig extends Omit<LogLayerTransportConfig<DataDogTransport$1>, "logger"> {
|
|
6
|
+
/**
|
|
7
|
+
* The options to pass to the datadog-transport-common instance.
|
|
8
|
+
*/
|
|
9
|
+
options: DDTransportOptions;
|
|
10
|
+
/**
|
|
11
|
+
* The field name to use for the message. Default is "message".
|
|
12
|
+
*/
|
|
13
|
+
messageField?: string;
|
|
14
|
+
/**
|
|
15
|
+
* The field name to use for the log level. Default is "level".
|
|
16
|
+
*/
|
|
17
|
+
levelField?: string;
|
|
18
|
+
/**
|
|
19
|
+
* The field name to use for the timestamp. Default is "time".
|
|
20
|
+
*/
|
|
21
|
+
timestampField?: string;
|
|
22
|
+
/**
|
|
23
|
+
* A custom function to stamp the timestamp
|
|
24
|
+
*/
|
|
25
|
+
timestampFunction?: () => any;
|
|
26
|
+
}
|
|
27
|
+
declare class DataDogTransport extends BaseTransport<DataDogTransport$1> {
|
|
28
|
+
messageField: string;
|
|
29
|
+
levelField: string;
|
|
30
|
+
timestampField: string;
|
|
31
|
+
timestampFunction?: () => any;
|
|
32
|
+
constructor(config: DatadogTransportConfig & Pick<LogLayerTransportConfig<DataDogTransport$1>, "logger">);
|
|
33
|
+
shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams): any[];
|
|
34
|
+
}
|
|
35
|
+
declare function createDataDogTransport(config: DatadogTransportConfig): DataDogTransport;
|
|
36
|
+
|
|
37
|
+
export { type DatadogTransportConfig, createDataDogTransport };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
// src/DataDogTransport.ts
|
|
2
|
+
import { BaseTransport } from "@loglayer/transport";
|
|
3
|
+
import { DataDogTransport as DatadogTransportCommon } from "datadog-transport-common";
|
|
4
|
+
var DataDogTransport = class extends BaseTransport {
|
|
5
|
+
messageField;
|
|
6
|
+
levelField;
|
|
7
|
+
timestampField;
|
|
8
|
+
timestampFunction;
|
|
9
|
+
constructor(config) {
|
|
10
|
+
super(config);
|
|
11
|
+
this.messageField = config.messageField ?? "message";
|
|
12
|
+
this.levelField = config.levelField ?? "level";
|
|
13
|
+
this.timestampField = config.timestampField ?? "time";
|
|
14
|
+
this.timestampFunction = config.timestampFunction;
|
|
15
|
+
}
|
|
16
|
+
shipToLogger({ logLevel, messages, data, hasData }) {
|
|
17
|
+
const logEntry = {};
|
|
18
|
+
if (data && hasData) {
|
|
19
|
+
Object.assign(logEntry, data);
|
|
20
|
+
}
|
|
21
|
+
if (this.timestampField && this.timestampFunction) {
|
|
22
|
+
logEntry[this.timestampField] = this.timestampFunction();
|
|
23
|
+
} else {
|
|
24
|
+
logEntry[this.timestampField] = (/* @__PURE__ */ new Date()).toISOString();
|
|
25
|
+
}
|
|
26
|
+
logEntry[this.levelField] = logLevel;
|
|
27
|
+
logEntry[this.messageField] = messages.join(" ");
|
|
28
|
+
this.logger.processLog(logEntry);
|
|
29
|
+
return messages;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
function createDataDogTransport(config) {
|
|
33
|
+
return new DataDogTransport({
|
|
34
|
+
...config,
|
|
35
|
+
logger: new DatadogTransportCommon(config.options)
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
export {
|
|
39
|
+
createDataDogTransport
|
|
40
|
+
};
|
|
41
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/DataDogTransport.ts"],"sourcesContent":["import { BaseTransport, type LogLayerTransportParams } from \"@loglayer/transport\";\nimport type { LogLayerTransportConfig } from \"@loglayer/transport\";\nimport { type DDTransportOptions, DataDogTransport as DatadogTransportCommon } from \"datadog-transport-common\";\n\nexport interface DatadogTransportConfig extends Omit<LogLayerTransportConfig<DatadogTransportCommon>, \"logger\"> {\n /**\n * The options to pass to the datadog-transport-common instance.\n */\n options: DDTransportOptions;\n /**\n * The field name to use for the message. Default is \"message\".\n */\n messageField?: string;\n /**\n * The field name to use for the log level. Default is \"level\".\n */\n levelField?: string;\n /**\n * The field name to use for the timestamp. Default is \"time\".\n */\n timestampField?: string;\n /**\n * A custom function to stamp the timestamp\n */\n timestampFunction?: () => any;\n}\n\nclass DataDogTransport extends BaseTransport<DatadogTransportCommon> {\n messageField: string;\n levelField: string;\n timestampField: string;\n timestampFunction?: () => any;\n\n constructor(config: DatadogTransportConfig & Pick<LogLayerTransportConfig<DatadogTransportCommon>, \"logger\">) {\n super(config);\n\n this.messageField = config.messageField ?? \"message\";\n this.levelField = config.levelField ?? \"level\";\n this.timestampField = config.timestampField ?? \"time\";\n this.timestampFunction = config.timestampFunction;\n }\n\n shipToLogger({ logLevel, messages, data, hasData }: LogLayerTransportParams) {\n const logEntry: Record<string, any> = {};\n\n if (data && hasData) {\n Object.assign(logEntry, data);\n }\n\n if (this.timestampField && this.timestampFunction) {\n logEntry[this.timestampField] = this.timestampFunction();\n } else {\n logEntry[this.timestampField] = new Date().toISOString();\n }\n\n logEntry[this.levelField] = logLevel;\n logEntry[this.messageField] = messages.join(\" \");\n\n this.logger.processLog(logEntry);\n\n return messages;\n }\n}\n\nexport function createDataDogTransport(config: DatadogTransportConfig) {\n return new DataDogTransport({\n ...config,\n logger: new DatadogTransportCommon(config.options),\n });\n}\n"],"mappings":";AAAA,SAAS,qBAAmD;AAE5D,SAAkC,oBAAoB,8BAA8B;AAyBpF,IAAM,mBAAN,cAA+B,cAAsC;AAAA,EACnE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAEA,YAAY,QAAkG;AAC5G,UAAM,MAAM;AAEZ,SAAK,eAAe,OAAO,gBAAgB;AAC3C,SAAK,aAAa,OAAO,cAAc;AACvC,SAAK,iBAAiB,OAAO,kBAAkB;AAC/C,SAAK,oBAAoB,OAAO;AAAA,EAClC;AAAA,EAEA,aAAa,EAAE,UAAU,UAAU,MAAM,QAAQ,GAA4B;AAC3E,UAAM,WAAgC,CAAC;AAEvC,QAAI,QAAQ,SAAS;AACnB,aAAO,OAAO,UAAU,IAAI;AAAA,IAC9B;AAEA,QAAI,KAAK,kBAAkB,KAAK,mBAAmB;AACjD,eAAS,KAAK,cAAc,IAAI,KAAK,kBAAkB;AAAA,IACzD,OAAO;AACL,eAAS,KAAK,cAAc,KAAI,oBAAI,KAAK,GAAE,YAAY;AAAA,IACzD;AAEA,aAAS,KAAK,UAAU,IAAI;AAC5B,aAAS,KAAK,YAAY,IAAI,SAAS,KAAK,GAAG;AAE/C,SAAK,OAAO,WAAW,QAAQ;AAE/B,WAAO;AAAA,EACT;AACF;AAEO,SAAS,uBAAuB,QAAgC;AACrE,SAAO,IAAI,iBAAiB;AAAA,IAC1B,GAAG;AAAA,IACH,QAAQ,IAAI,uBAAuB,OAAO,OAAO;AAAA,EACnD,CAAC;AACH;","names":[]}
|
package/package.json
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@loglayer/transport-datadog",
|
|
3
|
+
"description": "DataDog transport for loglayer.",
|
|
4
|
+
"version": "1.0.1",
|
|
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": "loglayer/loglayer.git",
|
|
21
|
+
"author": "Theo Gravity <theo@suteki.nu>",
|
|
22
|
+
"keywords": [
|
|
23
|
+
"logging",
|
|
24
|
+
"log",
|
|
25
|
+
"loglayer",
|
|
26
|
+
"datadog",
|
|
27
|
+
"transport"
|
|
28
|
+
],
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@datadog/datadog-api-client": "1.31.0",
|
|
31
|
+
"datadog-transport-common": "3.0.2",
|
|
32
|
+
"@loglayer/transport": "1.1.0"
|
|
33
|
+
},
|
|
34
|
+
"devDependencies": {
|
|
35
|
+
"hash-runner": "2.0.1",
|
|
36
|
+
"@types/node": "22.10.4",
|
|
37
|
+
"tsup": "8.3.5",
|
|
38
|
+
"typescript": "5.7.2",
|
|
39
|
+
"vitest": "2.1.8",
|
|
40
|
+
"loglayer": "5.0.4",
|
|
41
|
+
"@internal/tsconfig": "1.0.0"
|
|
42
|
+
},
|
|
43
|
+
"bugs": "https://github.com/loglayer/loglayer/issues",
|
|
44
|
+
"engines": {
|
|
45
|
+
"node": ">=18"
|
|
46
|
+
},
|
|
47
|
+
"files": [
|
|
48
|
+
"dist"
|
|
49
|
+
],
|
|
50
|
+
"homepage": "https://loglayer.dev",
|
|
51
|
+
"scripts": {
|
|
52
|
+
"build": "tsup src/index.ts",
|
|
53
|
+
"test": "vitest --run",
|
|
54
|
+
"build:dev": "hash-runner",
|
|
55
|
+
"clean": "rm -rf .turbo node_modules dist",
|
|
56
|
+
"lint": "biome check --write --unsafe src && biome format src --write && biome lint src --fix",
|
|
57
|
+
"verify-types": "tsc --noEmit"
|
|
58
|
+
}
|
|
59
|
+
}
|