@logbrew/sdk 0.1.37 → 0.1.39
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/automatic-delivery.cjs +271 -0
- package/batch-sender.cjs +164 -0
- package/bounded-number.cjs +34 -0
- package/browser-breadcrumbs.cjs +346 -136
- package/capture-support.cjs +100 -0
- package/client-options.cjs +292 -0
- package/client-report.cjs +232 -0
- package/client.cjs +447 -0
- package/console-arguments.cjs +151 -0
- package/console-capture.cjs +194 -0
- package/core.cjs +35 -2984
- package/delivery-health.cjs +133 -0
- package/error-causes.cjs +130 -0
- package/error-details.cjs +124 -0
- package/error-issue.cjs +187 -0
- package/event-clone.cjs +55 -0
- package/event-metadata.cjs +40 -0
- package/event-pipeline.cjs +325 -0
- package/event-queue.cjs +306 -0
- package/event-store.cjs +237 -0
- package/event-validation.cjs +159 -0
- package/examples/agent-timeline.cjs +57 -46
- package/examples/agent-timeline.mjs +41 -35
- package/examples/index.mjs +122 -94
- package/examples/readme-example.cjs +36 -27
- package/examples/readme-example.mjs +21 -17
- package/examples/real-user-smoke.cjs +41 -32
- package/examples/real-user-smoke.mjs +26 -22
- package/exception-chain.cjs +205 -0
- package/index.d.ts +144 -1076
- package/index.js +1 -1
- package/issue-breadcrumbs.cjs +143 -0
- package/issue-diagnostics.cjs +94 -582
- package/issue-evidence.cjs +256 -0
- package/issue-exception.cjs +268 -0
- package/issue-stack-frames.cjs +220 -0
- package/issue-stack-text.cjs +101 -0
- package/issue-stack.cjs +188 -225
- package/issue-text.cjs +72 -0
- package/log-context.cjs +87 -67
- package/metric-validation.cjs +95 -0
- package/network-milestone.cjs +155 -0
- package/null-value.cjs +4 -0
- package/opentelemetry-bridge.cjs +330 -0
- package/opentelemetry-context.cjs +245 -0
- package/opentelemetry-exceptions.cjs +69 -0
- package/opentelemetry-keys.cjs +183 -0
- package/opentelemetry-span.cjs +286 -0
- package/opentelemetry-summary.cjs +213 -0
- package/opentelemetry-time.cjs +131 -0
- package/opentelemetry.cjs +99 -1068
- package/package.json +64 -1
- package/pino-destination.cjs +108 -0
- package/pino-record.cjs +237 -0
- package/product-action.cjs +163 -0
- package/provided-breadcrumbs.cjs +117 -0
- package/random-hex.cjs +29 -0
- package/react-native.js +1 -1
- package/recording-transport.cjs +68 -0
- package/release-artifacts-build.cjs +263 -84
- package/release-artifacts-common.js +347 -66
- package/release-artifacts-debug-id.js +178 -0
- package/release-artifacts-inspect.js +213 -0
- package/release-artifacts-issue-event.js +99 -0
- package/release-artifacts-manifest-artifact.js +107 -0
- package/release-artifacts-manifest.js +77 -0
- package/release-artifacts-mappings.js +265 -0
- package/release-artifacts-prepare.js +297 -0
- package/release-artifacts-source-context.js +210 -0
- package/release-artifacts-symbolication.js +272 -421
- package/release-artifacts-upload-files.js +122 -0
- package/release-artifacts-upload-request.js +246 -0
- package/release-artifacts-upload.js +155 -300
- package/release-artifacts-urls.js +49 -0
- package/release-artifacts.js +189 -662
- package/retry-delay.cjs +32 -0
- package/sdk-error.cjs +36 -0
- package/span-validation.cjs +191 -0
- package/stored-events.cjs +243 -0
- package/support-ticket.cjs +232 -122
- package/telemetry-context.cjs +343 -251
- package/trace-context.cjs +376 -179
- package/transport-error.cjs +23 -0
- package/types/client.d.ts +67 -0
- package/types/delivery.d.ts +125 -0
- package/types/issues.d.ts +249 -0
- package/types/logging.d.ts +175 -0
- package/types/opentelemetry.d.ts +205 -0
- package/types/product.d.ts +128 -0
- package/types/recording-transport.d.ts +15 -0
- package/types/sdk-error.d.ts +9 -0
- package/types/telemetry.d.ts +171 -0
- package/types/trace-context.d.ts +110 -0
- package/types/transport-error.d.ts +10 -0
- package/utf8.cjs +37 -0
- package/validation.cjs +327 -0
- package/vite-release-artifacts-config.cjs +120 -0
- package/vite-release-artifacts.cjs +199 -99
- package/vite-release-artifacts.d.cts +65 -40
- package/vite-release-artifacts.d.ts +65 -40
- package/vite-release-artifacts.js +2 -2
- package/winston-info.cjs +205 -0
- package/winston.cjs +189 -290
package/winston-info.cjs
ADDED
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
const { compactMetadata, isMetadataValue, traceMetadataFromLogContext } = require("./log-context.cjs");
|
|
2
|
+
const { SdkError } = require("./sdk-error.cjs");
|
|
3
|
+
const { isObjectValue, isRecord, isTruthy, optionalProperty } = require("./validation.cjs");
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @import { Metadata, Severity } from "./index.cjs"
|
|
7
|
+
* @typedef {Readonly<{ includeErrorStack?: unknown, logger?: unknown, metadata?: unknown, trace?: unknown }>} WinstonInfoOptions
|
|
8
|
+
* @typedef {{ message: string, level: Severity, logger?: unknown, metadata: Metadata }} WinstonLogAttributes
|
|
9
|
+
* @typedef {Readonly<Record<string, unknown>>} WinstonInfo
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
const WINSTON_RESERVED_FIELDS = new Set(["level", "message", "timestamp", "time", "err", "error", "stack"]);
|
|
13
|
+
const LINE_BREAK_PATTERN = /\r?\n/u;
|
|
14
|
+
const FIRST_LINE = 0;
|
|
15
|
+
const STACK_HEADLINE_PATTERN = /^(?<name>[A-Za-z][A-Za-z0-9_.]*(?:Error|Exception)?):\s*(?<message>.*)$/u;
|
|
16
|
+
/** @type {ReadonlyMap<string, Severity>} */
|
|
17
|
+
const LOGBREW_LEVELS = new Map([
|
|
18
|
+
["warn", "warning"],
|
|
19
|
+
["warning", "warning"],
|
|
20
|
+
["error", "error"],
|
|
21
|
+
["crit", "critical"],
|
|
22
|
+
["critical", "critical"],
|
|
23
|
+
["fatal", "critical"]
|
|
24
|
+
]);
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @param {unknown} level
|
|
28
|
+
* @returns {Severity}
|
|
29
|
+
*/
|
|
30
|
+
function logbrewLevelFromWinstonLevel(level) {
|
|
31
|
+
return LOGBREW_LEVELS.get(String(level).toLowerCase()) ?? "info";
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {unknown} level
|
|
36
|
+
* @returns {string}
|
|
37
|
+
*/
|
|
38
|
+
function winstonLevelLabel(level) {
|
|
39
|
+
return typeof level === "string" && level.trim() !== "" ? level : "info";
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* @param {unknown} text
|
|
44
|
+
* @returns {text is string}
|
|
45
|
+
*/
|
|
46
|
+
function isNonBlankString(text) {
|
|
47
|
+
return typeof text === "string" && text.trim() !== "";
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {WinstonInfo} info
|
|
52
|
+
* @returns {string}
|
|
53
|
+
*/
|
|
54
|
+
function winstonMessage(info) {
|
|
55
|
+
if (isNonBlankString(info["message"])) {
|
|
56
|
+
return info["message"];
|
|
57
|
+
}
|
|
58
|
+
const error = info["err"] ?? info["error"];
|
|
59
|
+
if (isObjectValue(error) && isNonBlankString(error["message"])) {
|
|
60
|
+
return error["message"];
|
|
61
|
+
}
|
|
62
|
+
return "winston event";
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/**
|
|
66
|
+
* @param {WinstonInfo} info
|
|
67
|
+
* @returns {Metadata}
|
|
68
|
+
*/
|
|
69
|
+
function winstonContextMetadata(info) {
|
|
70
|
+
/** @type {Metadata} */
|
|
71
|
+
const metadata = {};
|
|
72
|
+
for (const [key, value] of Object.entries(info)) {
|
|
73
|
+
if (!WINSTON_RESERVED_FIELDS.has(key) && isMetadataValue(value)) {
|
|
74
|
+
metadata[`context.${key}`] = value;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return metadata;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/**
|
|
81
|
+
* @param {Readonly<Error>} error
|
|
82
|
+
* @param {boolean} includeErrorStack
|
|
83
|
+
* @returns {Metadata}
|
|
84
|
+
*/
|
|
85
|
+
function errorInstanceMetadata(error, includeErrorStack) {
|
|
86
|
+
return {
|
|
87
|
+
errorName: error.name || "Error",
|
|
88
|
+
...(error.message ? { errorMessage: error.message } : {}),
|
|
89
|
+
...(includeErrorStack && isTruthy(error.stack) ? { errorStack: error.stack } : {})
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* @param {Readonly<Record<string, unknown>>} error
|
|
95
|
+
* @param {boolean} includeErrorStack
|
|
96
|
+
* @returns {Metadata}
|
|
97
|
+
*/
|
|
98
|
+
function errorObjectMetadata(error, includeErrorStack) {
|
|
99
|
+
const name = error["type"] ?? error["name"];
|
|
100
|
+
const { message, stack } = error;
|
|
101
|
+
return {
|
|
102
|
+
...(isNonBlankString(name) ? { errorName: name } : {}),
|
|
103
|
+
...(isNonBlankString(message) ? { errorMessage: message } : {}),
|
|
104
|
+
...(includeErrorStack && isNonBlankString(stack) ? { errorStack: stack } : {})
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* @param {unknown} error
|
|
110
|
+
* @param {boolean} includeErrorStack
|
|
111
|
+
* @returns {Metadata}
|
|
112
|
+
*/
|
|
113
|
+
function nestedErrorMetadata(error, includeErrorStack) {
|
|
114
|
+
if (!isTruthy(error)) {
|
|
115
|
+
return {};
|
|
116
|
+
}
|
|
117
|
+
if (error instanceof Error) {
|
|
118
|
+
return errorInstanceMetadata(error, includeErrorStack);
|
|
119
|
+
}
|
|
120
|
+
if (isObjectValue(error)) {
|
|
121
|
+
return errorObjectMetadata(error, includeErrorStack);
|
|
122
|
+
}
|
|
123
|
+
return isNonBlankString(error) ? { errorMessage: error } : {};
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* @param {Readonly<Metadata>} metadata
|
|
128
|
+
* @param {string} stack
|
|
129
|
+
* @param {boolean} includeErrorStack
|
|
130
|
+
* @returns {Metadata}
|
|
131
|
+
*/
|
|
132
|
+
function stackMetadata(metadata, stack, includeErrorStack) {
|
|
133
|
+
const firstLine = stack.split(LINE_BREAK_PATTERN)[FIRST_LINE] ?? "";
|
|
134
|
+
const groups = STACK_HEADLINE_PATTERN.exec(firstLine)?.groups;
|
|
135
|
+
const name = groups?.["name"];
|
|
136
|
+
const message = groups?.["message"];
|
|
137
|
+
return {
|
|
138
|
+
...(name !== undefined && metadata["errorName"] === undefined ? { errorName: name } : {}),
|
|
139
|
+
...(message !== undefined && message !== "" && metadata["errorMessage"] === undefined ? { errorMessage: message } : {}),
|
|
140
|
+
...(includeErrorStack ? { errorStack: stack } : {})
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* @param {Readonly<Metadata>} metadata
|
|
146
|
+
* @param {WinstonInfo} info
|
|
147
|
+
* @param {boolean} includeErrorStack
|
|
148
|
+
* @returns {Metadata}
|
|
149
|
+
*/
|
|
150
|
+
function withWinstonErrorMetadata(metadata, info, includeErrorStack) {
|
|
151
|
+
const withError = { ...metadata, ...nestedErrorMetadata(info["err"] ?? info["error"], includeErrorStack) };
|
|
152
|
+
const { stack } = info;
|
|
153
|
+
return isNonBlankString(stack) ? { ...withError, ...stackMetadata(withError, stack, includeErrorStack) } : withError;
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* @param {unknown} info
|
|
158
|
+
* @param {WinstonInfoOptions} [options]
|
|
159
|
+
* @returns {WinstonLogAttributes}
|
|
160
|
+
*/
|
|
161
|
+
function logAttributesFromWinstonInfo(info, options = {}) {
|
|
162
|
+
if (!isRecord(info)) {
|
|
163
|
+
throw new SdkError("validation_error", "Winston info must be an object");
|
|
164
|
+
}
|
|
165
|
+
const level = logbrewLevelFromWinstonLevel(info["level"]);
|
|
166
|
+
const metadata = withWinstonErrorMetadata(
|
|
167
|
+
{
|
|
168
|
+
...compactMetadata(options.metadata),
|
|
169
|
+
winstonLevel: winstonLevelLabel(info["level"]),
|
|
170
|
+
...winstonContextMetadata(info),
|
|
171
|
+
...traceMetadataFromLogContext(options.trace)
|
|
172
|
+
},
|
|
173
|
+
info,
|
|
174
|
+
options.includeErrorStack === true
|
|
175
|
+
);
|
|
176
|
+
return {
|
|
177
|
+
message: winstonMessage(info),
|
|
178
|
+
|
|
179
|
+
level,
|
|
180
|
+
...(isTruthy(options.logger) ? { logger: options.logger } : {}),
|
|
181
|
+
metadata
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
/**
|
|
186
|
+
* @param {unknown} info
|
|
187
|
+
* @param {() => unknown} fallbackTimestamp
|
|
188
|
+
* @returns {unknown}
|
|
189
|
+
*/
|
|
190
|
+
function timestampFromWinstonInfo(info, fallbackTimestamp) {
|
|
191
|
+
const value = optionalProperty(info, "timestamp") ?? optionalProperty(info, "time");
|
|
192
|
+
if (typeof value === "number" && Number.isFinite(value)) {
|
|
193
|
+
return new Date(value).toISOString();
|
|
194
|
+
}
|
|
195
|
+
if (isNonBlankString(value)) {
|
|
196
|
+
const parsed = new Date(value);
|
|
197
|
+
return Number.isNaN(parsed.valueOf()) ? value : parsed.toISOString();
|
|
198
|
+
}
|
|
199
|
+
if (value instanceof Date && !Number.isNaN(value.valueOf())) {
|
|
200
|
+
return value.toISOString();
|
|
201
|
+
}
|
|
202
|
+
return fallbackTimestamp();
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
module.exports = { logAttributesFromWinstonInfo, timestampFromWinstonInfo, winstonMessage };
|