@logtape/otel 0.2.0 → 0.3.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/README.md +14 -0
- package/esm/deno.js +1 -1
- package/esm/mod.js +23 -5
- package/package.json +1 -1
- package/script/deno.js +1 -1
- package/script/mod.js +23 -5
- package/types/mod.d.ts +10 -2
- package/types/mod.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -151,6 +151,20 @@ needed.
|
|
|
151
151
|
Changelog
|
|
152
152
|
---------
|
|
153
153
|
|
|
154
|
+
### Version 0.3.0
|
|
155
|
+
|
|
156
|
+
Released on February 26, 2025.
|
|
157
|
+
|
|
158
|
+
- Now you can customize the body formatter. [[#1] by Hyeseong Kim]
|
|
159
|
+
|
|
160
|
+
- Added `BodyFormatter` type.
|
|
161
|
+
- Changed the type of `OpenTelemetrySinkOptions.messageType` to
|
|
162
|
+
`"string" | "array" | BodyFormatter | undefined` (was
|
|
163
|
+
`"string" | "array" | undefined`).
|
|
164
|
+
|
|
165
|
+
[#1]: https://github.com/dahlia/logtape-otel/pull/1
|
|
166
|
+
|
|
167
|
+
|
|
154
168
|
### Version 0.2.0
|
|
155
169
|
|
|
156
170
|
Released on August 26, 2024.
|
package/esm/deno.js
CHANGED
package/esm/mod.js
CHANGED
|
@@ -49,13 +49,14 @@ export function getOpenTelemetrySink(options = {}) {
|
|
|
49
49
|
const severityNumber = mapLevelToSeverityNumber(level);
|
|
50
50
|
const attributes = convertToAttributes(properties, objectRenderer);
|
|
51
51
|
attributes["category"] = [...category];
|
|
52
|
-
const body = convertMessageToBody(message, objectRenderer);
|
|
53
52
|
logger.emit({
|
|
54
53
|
severityNumber,
|
|
55
54
|
severityText: level,
|
|
56
|
-
body: options.messageType === "
|
|
57
|
-
?
|
|
58
|
-
:
|
|
55
|
+
body: typeof options.messageType === "function"
|
|
56
|
+
? convertMessageToCustomBodyFormat(message, objectRenderer, options.messageType)
|
|
57
|
+
: options.messageType === "array"
|
|
58
|
+
? convertMessageToArray(message, objectRenderer)
|
|
59
|
+
: convertMessageToString(message, objectRenderer),
|
|
59
60
|
attributes,
|
|
60
61
|
timestamp: new Date(timestamp),
|
|
61
62
|
});
|
|
@@ -124,7 +125,7 @@ function convertToString(value, objectRenderer) {
|
|
|
124
125
|
else
|
|
125
126
|
return JSON.stringify(value);
|
|
126
127
|
}
|
|
127
|
-
function
|
|
128
|
+
function convertMessageToArray(message, objectRenderer) {
|
|
128
129
|
const body = [];
|
|
129
130
|
for (let i = 0; i < message.length; i += 2) {
|
|
130
131
|
const msg = message[i];
|
|
@@ -136,6 +137,23 @@ function convertMessageToBody(message, objectRenderer) {
|
|
|
136
137
|
}
|
|
137
138
|
return body;
|
|
138
139
|
}
|
|
140
|
+
function convertMessageToString(message, objectRenderer) {
|
|
141
|
+
let body = "";
|
|
142
|
+
for (let i = 0; i < message.length; i += 2) {
|
|
143
|
+
const msg = message[i];
|
|
144
|
+
body += msg;
|
|
145
|
+
if (message.length <= i + 1)
|
|
146
|
+
break;
|
|
147
|
+
const val = message[i + 1];
|
|
148
|
+
const extra = convertToString(val, objectRenderer);
|
|
149
|
+
body += extra ?? JSON.stringify(extra);
|
|
150
|
+
}
|
|
151
|
+
return body;
|
|
152
|
+
}
|
|
153
|
+
function convertMessageToCustomBodyFormat(message, objectRenderer, bodyFormatter) {
|
|
154
|
+
const body = message.map((msg) => convertToString(msg, objectRenderer));
|
|
155
|
+
return bodyFormatter(body);
|
|
156
|
+
}
|
|
139
157
|
/**
|
|
140
158
|
* A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
|
|
141
159
|
* and in Node.js/Bun it is {@link util.inspect}. If neither is available, it
|
package/package.json
CHANGED
package/script/deno.js
CHANGED
package/script/mod.js
CHANGED
|
@@ -78,13 +78,14 @@ function getOpenTelemetrySink(options = {}) {
|
|
|
78
78
|
const severityNumber = mapLevelToSeverityNumber(level);
|
|
79
79
|
const attributes = convertToAttributes(properties, objectRenderer);
|
|
80
80
|
attributes["category"] = [...category];
|
|
81
|
-
const body = convertMessageToBody(message, objectRenderer);
|
|
82
81
|
logger.emit({
|
|
83
82
|
severityNumber,
|
|
84
83
|
severityText: level,
|
|
85
|
-
body: options.messageType === "
|
|
86
|
-
?
|
|
87
|
-
:
|
|
84
|
+
body: typeof options.messageType === "function"
|
|
85
|
+
? convertMessageToCustomBodyFormat(message, objectRenderer, options.messageType)
|
|
86
|
+
: options.messageType === "array"
|
|
87
|
+
? convertMessageToArray(message, objectRenderer)
|
|
88
|
+
: convertMessageToString(message, objectRenderer),
|
|
88
89
|
attributes,
|
|
89
90
|
timestamp: new Date(timestamp),
|
|
90
91
|
});
|
|
@@ -153,7 +154,7 @@ function convertToString(value, objectRenderer) {
|
|
|
153
154
|
else
|
|
154
155
|
return JSON.stringify(value);
|
|
155
156
|
}
|
|
156
|
-
function
|
|
157
|
+
function convertMessageToArray(message, objectRenderer) {
|
|
157
158
|
const body = [];
|
|
158
159
|
for (let i = 0; i < message.length; i += 2) {
|
|
159
160
|
const msg = message[i];
|
|
@@ -165,6 +166,23 @@ function convertMessageToBody(message, objectRenderer) {
|
|
|
165
166
|
}
|
|
166
167
|
return body;
|
|
167
168
|
}
|
|
169
|
+
function convertMessageToString(message, objectRenderer) {
|
|
170
|
+
let body = "";
|
|
171
|
+
for (let i = 0; i < message.length; i += 2) {
|
|
172
|
+
const msg = message[i];
|
|
173
|
+
body += msg;
|
|
174
|
+
if (message.length <= i + 1)
|
|
175
|
+
break;
|
|
176
|
+
const val = message[i + 1];
|
|
177
|
+
const extra = convertToString(val, objectRenderer);
|
|
178
|
+
body += extra ?? JSON.stringify(extra);
|
|
179
|
+
}
|
|
180
|
+
return body;
|
|
181
|
+
}
|
|
182
|
+
function convertMessageToCustomBodyFormat(message, objectRenderer, bodyFormatter) {
|
|
183
|
+
const body = message.map((msg) => convertToString(msg, objectRenderer));
|
|
184
|
+
return bodyFormatter(body);
|
|
185
|
+
}
|
|
168
186
|
/**
|
|
169
187
|
* A platform-specific inspect function. In Deno, this is {@link Deno.inspect},
|
|
170
188
|
* and in Node.js/Bun it is {@link util.inspect}. If neither is available, it
|
package/types/mod.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Sink } from "@logtape/logtape";
|
|
2
|
-
import { type LoggerProvider as LoggerProviderBase } from "@opentelemetry/api-logs";
|
|
2
|
+
import { type AnyValue, type LoggerProvider as LoggerProviderBase } from "@opentelemetry/api-logs";
|
|
3
3
|
import type { OTLPExporterNodeConfigBase } from "@opentelemetry/otlp-exporter-base";
|
|
4
4
|
import { type LogRecordProcessor } from "@opentelemetry/sdk-logs";
|
|
5
5
|
/**
|
|
@@ -26,6 +26,12 @@ type ILoggerProvider = LoggerProviderBase & {
|
|
|
26
26
|
* `Deno.inspect` in Deno.
|
|
27
27
|
*/
|
|
28
28
|
export type ObjectRenderer = "json" | "inspect";
|
|
29
|
+
type Message = (string | null | undefined)[];
|
|
30
|
+
/**
|
|
31
|
+
* Custom `body` attribute formatter.
|
|
32
|
+
* @since 0.3.0
|
|
33
|
+
*/
|
|
34
|
+
export type BodyFormatter = (message: Message) => AnyValue;
|
|
29
35
|
/**
|
|
30
36
|
* Options for creating an OpenTelemetry sink.
|
|
31
37
|
*/
|
|
@@ -39,9 +45,11 @@ export interface OpenTelemetrySinkOptions {
|
|
|
39
45
|
* the message is rendered as a single string with the values are
|
|
40
46
|
* interpolated into the message. If `"array"`, the message is
|
|
41
47
|
* rendered as an array of strings. `"string"` by default.
|
|
48
|
+
*
|
|
49
|
+
* Or even fully customizable with a {@link BodyFormatter} function.
|
|
42
50
|
* @since 0.2.0
|
|
43
51
|
*/
|
|
44
|
-
messageType?: "string" | "array";
|
|
52
|
+
messageType?: "string" | "array" | BodyFormatter;
|
|
45
53
|
/**
|
|
46
54
|
* The way to render the object in the log record. If `"json"`,
|
|
47
55
|
* the object is rendered as a JSON string. If `"inspect"`,
|
package/types/mod.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,
|
|
1
|
+
{"version":3,"file":"mod.d.ts","sourceRoot":"","sources":["../src/mod.ts"],"names":[],"mappings":"AACA,OAAO,EAIL,KAAK,IAAI,EACV,MAAM,kBAAkB,CAAC;AAE1B,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,IAAI,kBAAkB,EAG1C,MAAM,yBAAyB,CAAC;AAEjC,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAC;AAEpF,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,yBAAyB,CAAC;AAKjC;;GAEG;AACH,KAAK,eAAe,GAAG,kBAAkB,GAAG;IAC1C;;;OAGG;IACH,qBAAqB,CAAC,SAAS,EAAE,kBAAkB,GAAG,IAAI,CAAC;IAE3D;;;;;OAKG;IACH,QAAQ,CAAC,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC,CAAC;AAEF;;;;;GAKG;AACH,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,SAAS,CAAC;AAEhD,KAAK,OAAO,GAAG,CAAC,MAAM,GAAG,IAAI,GAAG,SAAS,CAAC,EAAE,CAAC;AAE7C;;;GAGG;AACH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,EAAE,OAAO,KAAK,QAAQ,CAAC;AAE3D;;GAEG;AACH,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,cAAc,CAAC,EAAE,eAAe,CAAC;IAEjC;;;;;;;;OAQG;IACH,WAAW,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,aAAa,CAAC;IAEjD;;;;;OAKG;IACH,cAAc,CAAC,EAAE,cAAc,CAAC;IAEhC;;;;OAIG;IACH,WAAW,CAAC,EAAE,OAAO,CAAC;IAEtB;;;OAGG;IACH,kBAAkB,CAAC,EAAE,0BAA0B,CAAC;IAEhD;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,OAAO,GAAE,wBAA6B,GACrC,IAAI,CA0DN"}
|