@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.
Files changed (90) hide show
  1. package/automatic-delivery.cjs +271 -0
  2. package/batch-sender.cjs +164 -0
  3. package/bounded-number.cjs +34 -0
  4. package/browser-breadcrumbs.cjs +346 -136
  5. package/capture-support.cjs +100 -0
  6. package/client-options.cjs +292 -0
  7. package/client-report.cjs +232 -0
  8. package/client.cjs +447 -0
  9. package/console-arguments.cjs +151 -0
  10. package/console-capture.cjs +194 -0
  11. package/core.cjs +30 -2810
  12. package/delivery-health.cjs +133 -0
  13. package/error-causes.cjs +130 -0
  14. package/error-details.cjs +124 -0
  15. package/error-issue.cjs +187 -0
  16. package/event-clone.cjs +55 -0
  17. package/event-metadata.cjs +40 -0
  18. package/event-pipeline.cjs +325 -0
  19. package/event-queue.cjs +306 -0
  20. package/event-store.cjs +237 -0
  21. package/event-validation.cjs +159 -0
  22. package/examples/agent-timeline.cjs +57 -46
  23. package/examples/agent-timeline.mjs +41 -35
  24. package/examples/index.mjs +122 -94
  25. package/examples/readme-example.cjs +36 -27
  26. package/examples/readme-example.mjs +21 -17
  27. package/examples/real-user-smoke.cjs +41 -32
  28. package/examples/real-user-smoke.mjs +26 -22
  29. package/exception-chain.cjs +205 -0
  30. package/index.d.ts +144 -1076
  31. package/index.js +1 -1
  32. package/issue-exception.cjs +13 -8
  33. package/metric-validation.cjs +95 -0
  34. package/network-milestone.cjs +155 -0
  35. package/null-value.cjs +4 -0
  36. package/opentelemetry-bridge.cjs +330 -0
  37. package/opentelemetry-context.cjs +245 -0
  38. package/opentelemetry-exceptions.cjs +69 -0
  39. package/opentelemetry-keys.cjs +183 -0
  40. package/opentelemetry-span.cjs +286 -0
  41. package/opentelemetry-summary.cjs +213 -0
  42. package/opentelemetry-time.cjs +131 -0
  43. package/opentelemetry.cjs +99 -1068
  44. package/package.json +55 -1
  45. package/pino-destination.cjs +108 -0
  46. package/pino-record.cjs +237 -0
  47. package/product-action.cjs +163 -0
  48. package/provided-breadcrumbs.cjs +117 -0
  49. package/random-hex.cjs +29 -0
  50. package/react-native.js +1 -1
  51. package/recording-transport.cjs +68 -0
  52. package/release-artifacts-build.cjs +263 -84
  53. package/release-artifacts-common.js +347 -66
  54. package/release-artifacts-debug-id.js +178 -0
  55. package/release-artifacts-inspect.js +213 -0
  56. package/release-artifacts-issue-event.js +99 -0
  57. package/release-artifacts-manifest-artifact.js +107 -0
  58. package/release-artifacts-manifest.js +77 -0
  59. package/release-artifacts-mappings.js +265 -0
  60. package/release-artifacts-prepare.js +297 -0
  61. package/release-artifacts-source-context.js +210 -0
  62. package/release-artifacts-symbolication.js +272 -421
  63. package/release-artifacts-upload-files.js +122 -0
  64. package/release-artifacts-upload-request.js +246 -0
  65. package/release-artifacts-upload.js +155 -300
  66. package/release-artifacts-urls.js +49 -0
  67. package/release-artifacts.js +189 -662
  68. package/retry-delay.cjs +32 -0
  69. package/span-validation.cjs +191 -0
  70. package/stored-events.cjs +243 -0
  71. package/types/client.d.ts +67 -0
  72. package/types/delivery.d.ts +125 -0
  73. package/types/issues.d.ts +249 -0
  74. package/types/logging.d.ts +175 -0
  75. package/types/opentelemetry.d.ts +205 -0
  76. package/types/product.d.ts +128 -0
  77. package/types/recording-transport.d.ts +15 -0
  78. package/types/sdk-error.d.ts +9 -0
  79. package/types/telemetry.d.ts +171 -0
  80. package/types/trace-context.d.ts +110 -0
  81. package/types/transport-error.d.ts +10 -0
  82. package/utf8.cjs +37 -0
  83. package/validation.cjs +49 -1
  84. package/vite-release-artifacts-config.cjs +120 -0
  85. package/vite-release-artifacts.cjs +199 -99
  86. package/vite-release-artifacts.d.cts +65 -40
  87. package/vite-release-artifacts.d.ts +65 -40
  88. package/vite-release-artifacts.js +2 -2
  89. package/winston-info.cjs +205 -0
  90. 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 };