@logbrew/sdk 0.1.38 → 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 +30 -2810
- 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-exception.cjs +13 -8
- 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 +55 -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/span-validation.cjs +191 -0
- package/stored-events.cjs +243 -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 +49 -1
- 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 -289
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const { captureSettings, settledFlush } = require("./capture-support.cjs");
|
|
2
|
+
const { LogBrewClient } = require("./client.cjs");
|
|
3
|
+
const { CONSOLE_METHODS, logAttributesFromConsoleArgs } = require("./console-arguments.cjs");
|
|
4
|
+
const { NULL_VALUE } = require("./null-value.cjs");
|
|
5
|
+
const { SdkError } = require("./sdk-error.cjs");
|
|
6
|
+
const { isObjectValue, isTruthy } = require("./validation.cjs");
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @import { ConsoleMethodName } from "./index.cjs"
|
|
10
|
+
* @import { CaptureClient } from "./capture-support.cjs"
|
|
11
|
+
* @typedef {(this: unknown, ...args: readonly unknown[]) => void} ConsoleMethod
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
const NO_PENDING_EVENTS = 0;
|
|
15
|
+
/** @type {readonly ConsoleMethodName[]} */
|
|
16
|
+
const DEFAULT_CONSOLE_LEVELS = ["debug", "info", "log", "warn", "error"];
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* @param {unknown} method
|
|
20
|
+
* @returns {ConsoleMethodName}
|
|
21
|
+
*/
|
|
22
|
+
function requireConsoleMethod(method) {
|
|
23
|
+
const level = [...CONSOLE_METHODS].find((name) => name === method);
|
|
24
|
+
if (level === undefined) {
|
|
25
|
+
throw new SdkError("validation_error", `console method must be one of: ${[...CONSOLE_METHODS].join(", ")}`);
|
|
26
|
+
}
|
|
27
|
+
return level;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {unknown} levels
|
|
32
|
+
* @returns {ConsoleMethodName[]}
|
|
33
|
+
*/
|
|
34
|
+
function normalizeConsoleLevels(levels) {
|
|
35
|
+
const requestedLevels = levels === undefined ? DEFAULT_CONSOLE_LEVELS : levels;
|
|
36
|
+
if (!Array.isArray(requestedLevels)) {
|
|
37
|
+
throw new SdkError("validation_error", "console capture levels must be an array");
|
|
38
|
+
}
|
|
39
|
+
/** @type {ConsoleMethodName[]} */
|
|
40
|
+
const normalized = [];
|
|
41
|
+
/** @type {readonly unknown[]} */
|
|
42
|
+
const methods = requestedLevels;
|
|
43
|
+
for (const method of methods) {
|
|
44
|
+
const level = requireConsoleMethod(method);
|
|
45
|
+
if (!normalized.includes(level)) {
|
|
46
|
+
normalized.push(level);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return normalized;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* @param {unknown} original
|
|
54
|
+
* @param {(args: readonly unknown[]) => void} record
|
|
55
|
+
* @returns {ConsoleMethod}
|
|
56
|
+
*/
|
|
57
|
+
function consoleMethod(original, record) {
|
|
58
|
+
/** @type {ConsoleMethod} */
|
|
59
|
+
function logBrewConsoleMethod(...args) {
|
|
60
|
+
if (typeof original === "function") {
|
|
61
|
+
Reflect.apply(original, this, args);
|
|
62
|
+
}
|
|
63
|
+
record(args);
|
|
64
|
+
}
|
|
65
|
+
return logBrewConsoleMethod;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
class ConsoleCapture {
|
|
69
|
+
/**
|
|
70
|
+
* @param {Readonly<Record<string, unknown>>} config
|
|
71
|
+
* @param {CaptureClient} client
|
|
72
|
+
* @param {object} targetConsole
|
|
73
|
+
*/
|
|
74
|
+
constructor(config, client, targetConsole) {
|
|
75
|
+
this.client = client;
|
|
76
|
+
this.targetConsole = targetConsole;
|
|
77
|
+
this.settings = captureSettings(config, "flushOnCapture", "console");
|
|
78
|
+
this.levels = normalizeConsoleLevels(config["levels"]);
|
|
79
|
+
/** @type {Map<ConsoleMethodName, unknown>} */
|
|
80
|
+
this.originals = new Map();
|
|
81
|
+
this.installed = true;
|
|
82
|
+
this.captured = 0;
|
|
83
|
+
/** @type {Promise<unknown>} */
|
|
84
|
+
this.pendingFlush = Promise.resolve(NULL_VALUE);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* @returns {void}
|
|
89
|
+
*/
|
|
90
|
+
install() {
|
|
91
|
+
for (const method of this.levels) {
|
|
92
|
+
/** @type {unknown} */
|
|
93
|
+
const original = Reflect.get(this.targetConsole, method);
|
|
94
|
+
if (typeof original === "function") {
|
|
95
|
+
this.originals.set(method, original);
|
|
96
|
+
Reflect.set(this.targetConsole, method, consoleMethod(original, (args) => {
|
|
97
|
+
this.record(method, args);
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/**
|
|
104
|
+
* @param {ConsoleMethodName} method
|
|
105
|
+
* @param {readonly unknown[]} args
|
|
106
|
+
* @returns {void}
|
|
107
|
+
*/
|
|
108
|
+
record(method, args) {
|
|
109
|
+
if (!this.installed) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
const { settings } = this;
|
|
113
|
+
try {
|
|
114
|
+
this.captured += 1;
|
|
115
|
+
this.client.log(
|
|
116
|
+
`${String(settings.eventIdPrefix)}_${this.captured}`,
|
|
117
|
+
settings.timestamp(),
|
|
118
|
+
logAttributesFromConsoleArgs(method, args, {
|
|
119
|
+
includeErrorStack: settings.includeErrorStack,
|
|
120
|
+
logger: settings.logger,
|
|
121
|
+
metadata: settings.metadata
|
|
122
|
+
})
|
|
123
|
+
);
|
|
124
|
+
if (settings.flushOnEvent && isTruthy(settings.transport)) {
|
|
125
|
+
this.pendingFlush = settledFlush(this.client.flush(settings.transport), settings.onError);
|
|
126
|
+
}
|
|
127
|
+
} catch (error) {
|
|
128
|
+
settings.onError(error);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* @returns {void}
|
|
134
|
+
*/
|
|
135
|
+
flushPending() {
|
|
136
|
+
const { settings } = this;
|
|
137
|
+
if (isTruthy(settings.transport) && this.client.pendingEvents() > NO_PENDING_EVENTS) {
|
|
138
|
+
this.pendingFlush = settledFlush(this.client.flush(settings.transport), settings.onError);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/**
|
|
143
|
+
* @returns {void}
|
|
144
|
+
*/
|
|
145
|
+
uninstall() {
|
|
146
|
+
if (!this.installed) {
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
this.installed = false;
|
|
150
|
+
for (const [method, original] of this.originals.entries()) {
|
|
151
|
+
Reflect.set(this.targetConsole, method, original);
|
|
152
|
+
}
|
|
153
|
+
this.originals.clear();
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
/**
|
|
158
|
+
* @param {Readonly<Record<string, unknown>>} config
|
|
159
|
+
* @returns {object}
|
|
160
|
+
*/
|
|
161
|
+
function targetConsoleFrom(config) {
|
|
162
|
+
const targetConsole = config["console"] ?? globalThis.console;
|
|
163
|
+
if (!isObjectValue(targetConsole)) {
|
|
164
|
+
throw new SdkError("validation_error", "console capture target must be an object");
|
|
165
|
+
}
|
|
166
|
+
return targetConsole;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* @param {unknown} config
|
|
171
|
+
* @returns {{ flush: () => Promise<unknown>, uninstall: () => void }}
|
|
172
|
+
*/
|
|
173
|
+
function installLogBrewConsoleCapture(config) {
|
|
174
|
+
if (!isObjectValue(config)) {
|
|
175
|
+
throw new SdkError("validation_error", "console capture config must be an object");
|
|
176
|
+
}
|
|
177
|
+
const { client } = config;
|
|
178
|
+
if (!(client instanceof LogBrewClient)) {
|
|
179
|
+
throw new SdkError("validation_error", "console capture client must be a LogBrewClient");
|
|
180
|
+
}
|
|
181
|
+
const capture = new ConsoleCapture(config, client, targetConsoleFrom(config));
|
|
182
|
+
capture.install();
|
|
183
|
+
return {
|
|
184
|
+
flush: async () => {
|
|
185
|
+
capture.flushPending();
|
|
186
|
+
return capture.pendingFlush;
|
|
187
|
+
},
|
|
188
|
+
uninstall: () => {
|
|
189
|
+
capture.uninstall();
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
module.exports = { installLogBrewConsoleCapture };
|