@remote-logger/sdk 0.1.5 → 0.1.7

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 CHANGED
@@ -144,6 +144,33 @@ logger.restoreConsole();
144
144
 
145
145
  This wraps `console.debug`, `console.log`, `console.info`, and `console.warn`. Errors are captured via `window.addEventListener('error')` and `unhandledrejection` listeners instead of wrapping `console.error`, to avoid polluting stack traces in frameworks like Next.js/React.
146
146
 
147
+ ## Source Map Support (Vite)
148
+
149
+ Automatically resolve minified production stack traces back to original source. The Vite plugin uploads source maps at build time, and the ingestion service resolves stack traces before storing them.
150
+
151
+ ```ts
152
+ // vite.config.ts
153
+ import remoteLoggerPlugin from '@remote-logger/sdk/vite';
154
+
155
+ export default defineConfig({
156
+ plugins: [
157
+ remoteLoggerPlugin({
158
+ apiKey: process.env.REMOTE_LOGGER_API_KEY!,
159
+ logFileId: 'your-log-file-id',
160
+ }),
161
+ ],
162
+ build: { sourcemap: true },
163
+ });
164
+ ```
165
+
166
+ The plugin:
167
+ - **Skips in dev mode** — stacks are already readable
168
+ - **Generates a release UUID** per build, injected as `__REMOTE_LOGGER_RELEASE__`
169
+ - **Uploads `.map` files** from the build output to the ingestion service on `closeBundle`
170
+ - **Multi-bundle (Electron):** All plugin instances in the same Node process share one release ID, so main + renderer maps are grouped under the same release
171
+
172
+ No SDK configuration needed — the SDK automatically detects `__REMOTE_LOGGER_RELEASE__` and attaches it to every log entry.
173
+
147
174
  ## AI Assistant Integration
148
175
 
149
176
  Run the init command to configure your AI coding assistant (Claude Code, Cursor, etc.) to use the SDK:
package/SKILL.md CHANGED
@@ -113,8 +113,13 @@ SELECT timestamp, group, level, message FROM logs.entries WHERE trace_id = 'req-
113
113
 
114
114
  -- Recent logs from a specific group
115
115
  SELECT timestamp, level, message FROM logs.entries WHERE group = 'auth' ORDER BY timestamp DESC LIMIT 50
116
+
117
+ -- Error with source context (see the original code around the error)
118
+ SELECT timestamp, message, stack, source_context FROM logs.entries WHERE level = 'ERROR' AND source_context IS NOT NULL ORDER BY timestamp DESC LIMIT 5
116
119
  ```
117
120
 
121
+ **Tip:** When investigating production errors, include `source_context` in your SELECT. It contains the original source code around the error line (resolved from source maps at ingestion time), so you can see exactly what code triggered the error without needing to open the file.
122
+
118
123
  ### Table Schema
119
124
 
120
125
  ```
@@ -124,8 +129,10 @@ level String -- DEBUG, INFO, WARN, ERROR, FATAL
124
129
  trace_id String -- request correlation
125
130
  group String -- categorization (e.g., 'api/billing', 'main', 'renderer')
126
131
  message String -- log content
127
- stack Nullable(String) -- stack trace
132
+ stack Nullable(String) -- stack trace (resolved via source maps if available)
128
133
  error_type String -- exception class name
134
+ release_id String -- build release ID (for source map resolution)
135
+ source_context String -- JSON: { file, line, code: { "lineNum": "source line" } } — original source around the error
129
136
  metadata JSON -- arbitrary structured data
130
137
  ```
131
138
 
@@ -0,0 +1,11 @@
1
+ var __typeError = (msg) => {
2
+ throw TypeError(msg);
3
+ };
4
+ var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
+ var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
6
+ var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
7
+
8
+ export {
9
+ __privateAdd,
10
+ __privateMethod
11
+ };
package/dist/index.d.mts CHANGED
@@ -27,6 +27,7 @@ interface InternalLogEntry {
27
27
  trace_id?: string;
28
28
  stack?: string;
29
29
  error_type?: string;
30
+ release_id?: string;
30
31
  metadata?: Record<string, unknown>;
31
32
  }
32
33
  /** Object form for logger.info({ message, group?, metadata? }) */
package/dist/index.d.ts CHANGED
@@ -27,6 +27,7 @@ interface InternalLogEntry {
27
27
  trace_id?: string;
28
28
  stack?: string;
29
29
  error_type?: string;
30
+ release_id?: string;
30
31
  metadata?: Record<string, unknown>;
31
32
  }
32
33
  /** Object form for logger.info({ message, group?, metadata? }) */
package/dist/index.js CHANGED
@@ -339,6 +339,7 @@ function isErrorLike(value) {
339
339
  }
340
340
 
341
341
  // src/index.ts
342
+ var RELEASE_ID = typeof __REMOTE_LOGGER_RELEASE__ !== "undefined" ? __REMOTE_LOGGER_RELEASE__ : void 0;
342
343
  var LEVEL_ORDER = {
343
344
  DEBUG: 0,
344
345
  INFO: 1,
@@ -519,6 +520,7 @@ ${arg.stack}`;
519
520
  trace_id: options?.traceId ?? this.config.traceId,
520
521
  stack: options?.stack,
521
522
  error_type: options?.errorType,
523
+ release_id: RELEASE_ID,
522
524
  metadata: options?.metadata
523
525
  };
524
526
  this.buffer.push(entry);
package/dist/index.mjs CHANGED
@@ -1,9 +1,7 @@
1
- var __typeError = (msg) => {
2
- throw TypeError(msg);
3
- };
4
- var __accessCheck = (obj, member, msg) => member.has(obj) || __typeError("Cannot " + msg);
5
- var __privateAdd = (obj, member, value) => member.has(obj) ? __typeError("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
6
- var __privateMethod = (obj, member, method) => (__accessCheck(obj, member, "access private method"), method);
1
+ import {
2
+ __privateAdd,
3
+ __privateMethod
4
+ } from "./chunk-JKIIIVNW.mjs";
7
5
 
8
6
  // ../node_modules/non-error/index.js
9
7
  var isNonErrorSymbol = /* @__PURE__ */ Symbol("isNonError");
@@ -312,6 +310,7 @@ function isErrorLike(value) {
312
310
  }
313
311
 
314
312
  // src/index.ts
313
+ var RELEASE_ID = typeof __REMOTE_LOGGER_RELEASE__ !== "undefined" ? __REMOTE_LOGGER_RELEASE__ : void 0;
315
314
  var LEVEL_ORDER = {
316
315
  DEBUG: 0,
317
316
  INFO: 1,
@@ -492,6 +491,7 @@ ${arg.stack}`;
492
491
  trace_id: options?.traceId ?? this.config.traceId,
493
492
  stack: options?.stack,
494
493
  error_type: options?.errorType,
494
+ release_id: RELEASE_ID,
495
495
  metadata: options?.metadata
496
496
  };
497
497
  this.buffer.push(entry);
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface RemoteLoggerPluginOptions {
4
+ apiKey: string;
5
+ logFileId: string;
6
+ /** @internal Override endpoint for development */
7
+ _endpoint?: string;
8
+ }
9
+ declare function remoteLoggerPlugin(options: RemoteLoggerPluginOptions): Plugin;
10
+
11
+ export { type RemoteLoggerPluginOptions, remoteLoggerPlugin as default };
package/dist/vite.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { Plugin } from 'vite';
2
+
3
+ interface RemoteLoggerPluginOptions {
4
+ apiKey: string;
5
+ logFileId: string;
6
+ /** @internal Override endpoint for development */
7
+ _endpoint?: string;
8
+ }
9
+ declare function remoteLoggerPlugin(options: RemoteLoggerPluginOptions): Plugin;
10
+
11
+ export { type RemoteLoggerPluginOptions, remoteLoggerPlugin as default };
package/dist/vite.js ADDED
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/vite.ts
21
+ var vite_exports = {};
22
+ __export(vite_exports, {
23
+ default: () => remoteLoggerPlugin
24
+ });
25
+ module.exports = __toCommonJS(vite_exports);
26
+ var import_crypto = require("crypto");
27
+ var import_fs = require("fs");
28
+ var import_path = require("path");
29
+ var DEFAULT_ENDPOINT = "https://log.terodato.com";
30
+ function collectMapFiles(dir) {
31
+ const results = [];
32
+ try {
33
+ const entries = (0, import_fs.readdirSync)(dir, { withFileTypes: true });
34
+ for (const entry of entries) {
35
+ const fullPath = (0, import_path.join)(dir, entry.name);
36
+ if (entry.isDirectory()) {
37
+ results.push(...collectMapFiles(fullPath));
38
+ } else if (entry.name.endsWith(".map")) {
39
+ results.push(fullPath);
40
+ }
41
+ }
42
+ } catch {
43
+ }
44
+ return results;
45
+ }
46
+ var sharedReleaseId = null;
47
+ var uploadedOutDirs = /* @__PURE__ */ new Set();
48
+ function remoteLoggerPlugin(options) {
49
+ if (!sharedReleaseId) sharedReleaseId = (0, import_crypto.randomUUID)();
50
+ const releaseId = sharedReleaseId;
51
+ let resolvedConfig;
52
+ let skip = false;
53
+ return {
54
+ name: "remote-logger-sourcemap",
55
+ enforce: "post",
56
+ config(config, { command, mode }) {
57
+ if (mode === "development" || command === "serve") {
58
+ skip = true;
59
+ return;
60
+ }
61
+ return {
62
+ define: {
63
+ __REMOTE_LOGGER_RELEASE__: JSON.stringify(releaseId)
64
+ }
65
+ };
66
+ },
67
+ configResolved(config) {
68
+ resolvedConfig = config;
69
+ },
70
+ async closeBundle() {
71
+ if (skip) return;
72
+ const outDir = resolvedConfig.build.outDir;
73
+ if (uploadedOutDirs.has(outDir)) return;
74
+ uploadedOutDirs.add(outDir);
75
+ const mapFiles = collectMapFiles(outDir);
76
+ if (mapFiles.length === 0) {
77
+ console.log("[RemoteLogger] No source map files found, skipping upload");
78
+ return;
79
+ }
80
+ const endpoint = options._endpoint || DEFAULT_ENDPOINT;
81
+ const url = `${endpoint}/sourcemaps/upload`;
82
+ const formData = new FormData();
83
+ formData.append("releaseId", releaseId);
84
+ formData.append("logFileId", options.logFileId);
85
+ for (const mapFile of mapFiles) {
86
+ const content = (0, import_fs.readFileSync)(mapFile);
87
+ const name = (0, import_path.relative)(outDir, mapFile).replace(/\\/g, "/").replace(/\//g, "_");
88
+ const blob = new Blob([content], { type: "application/json" });
89
+ formData.append("files", blob, name.endsWith(".map") ? name : `${name}.map`);
90
+ }
91
+ try {
92
+ console.log(`[RemoteLogger] Uploading ${mapFiles.length} source maps (release: ${releaseId})...`);
93
+ const response = await fetch(url, {
94
+ method: "POST",
95
+ headers: {
96
+ "Authorization": `Bearer ${options.apiKey}`
97
+ },
98
+ body: formData
99
+ });
100
+ if (!response.ok) {
101
+ const body = await response.text();
102
+ console.error(`[RemoteLogger] Source map upload failed (${response.status}): ${body}`);
103
+ return;
104
+ }
105
+ const result = await response.json();
106
+ console.log(`[RemoteLogger] Uploaded ${result.count} source maps successfully`);
107
+ } catch (err) {
108
+ console.error("[RemoteLogger] Source map upload failed:", err);
109
+ }
110
+ }
111
+ };
112
+ }
package/dist/vite.mjs ADDED
@@ -0,0 +1,93 @@
1
+ import "./chunk-JKIIIVNW.mjs";
2
+
3
+ // src/vite.ts
4
+ import { randomUUID } from "crypto";
5
+ import { readdirSync, readFileSync } from "fs";
6
+ import { join, relative } from "path";
7
+ var DEFAULT_ENDPOINT = "https://log.terodato.com";
8
+ function collectMapFiles(dir) {
9
+ const results = [];
10
+ try {
11
+ const entries = readdirSync(dir, { withFileTypes: true });
12
+ for (const entry of entries) {
13
+ const fullPath = join(dir, entry.name);
14
+ if (entry.isDirectory()) {
15
+ results.push(...collectMapFiles(fullPath));
16
+ } else if (entry.name.endsWith(".map")) {
17
+ results.push(fullPath);
18
+ }
19
+ }
20
+ } catch {
21
+ }
22
+ return results;
23
+ }
24
+ var sharedReleaseId = null;
25
+ var uploadedOutDirs = /* @__PURE__ */ new Set();
26
+ function remoteLoggerPlugin(options) {
27
+ if (!sharedReleaseId) sharedReleaseId = randomUUID();
28
+ const releaseId = sharedReleaseId;
29
+ let resolvedConfig;
30
+ let skip = false;
31
+ return {
32
+ name: "remote-logger-sourcemap",
33
+ enforce: "post",
34
+ config(config, { command, mode }) {
35
+ if (mode === "development" || command === "serve") {
36
+ skip = true;
37
+ return;
38
+ }
39
+ return {
40
+ define: {
41
+ __REMOTE_LOGGER_RELEASE__: JSON.stringify(releaseId)
42
+ }
43
+ };
44
+ },
45
+ configResolved(config) {
46
+ resolvedConfig = config;
47
+ },
48
+ async closeBundle() {
49
+ if (skip) return;
50
+ const outDir = resolvedConfig.build.outDir;
51
+ if (uploadedOutDirs.has(outDir)) return;
52
+ uploadedOutDirs.add(outDir);
53
+ const mapFiles = collectMapFiles(outDir);
54
+ if (mapFiles.length === 0) {
55
+ console.log("[RemoteLogger] No source map files found, skipping upload");
56
+ return;
57
+ }
58
+ const endpoint = options._endpoint || DEFAULT_ENDPOINT;
59
+ const url = `${endpoint}/sourcemaps/upload`;
60
+ const formData = new FormData();
61
+ formData.append("releaseId", releaseId);
62
+ formData.append("logFileId", options.logFileId);
63
+ for (const mapFile of mapFiles) {
64
+ const content = readFileSync(mapFile);
65
+ const name = relative(outDir, mapFile).replace(/\\/g, "/").replace(/\//g, "_");
66
+ const blob = new Blob([content], { type: "application/json" });
67
+ formData.append("files", blob, name.endsWith(".map") ? name : `${name}.map`);
68
+ }
69
+ try {
70
+ console.log(`[RemoteLogger] Uploading ${mapFiles.length} source maps (release: ${releaseId})...`);
71
+ const response = await fetch(url, {
72
+ method: "POST",
73
+ headers: {
74
+ "Authorization": `Bearer ${options.apiKey}`
75
+ },
76
+ body: formData
77
+ });
78
+ if (!response.ok) {
79
+ const body = await response.text();
80
+ console.error(`[RemoteLogger] Source map upload failed (${response.status}): ${body}`);
81
+ return;
82
+ }
83
+ const result = await response.json();
84
+ console.log(`[RemoteLogger] Uploaded ${result.count} source maps successfully`);
85
+ } catch (err) {
86
+ console.error("[RemoteLogger] Source map upload failed:", err);
87
+ }
88
+ }
89
+ };
90
+ }
91
+ export {
92
+ remoteLoggerPlugin as default
93
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remote-logger/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.7",
4
4
  "description": "JavaScript SDK for Remote Logger",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -10,6 +10,11 @@
10
10
  "types": "./dist/index.d.ts",
11
11
  "require": "./dist/index.js",
12
12
  "import": "./dist/index.mjs"
13
+ },
14
+ "./vite": {
15
+ "types": "./dist/vite.d.ts",
16
+ "require": "./dist/vite.js",
17
+ "import": "./dist/vite.mjs"
13
18
  }
14
19
  },
15
20
  "bin": {
@@ -20,7 +25,7 @@
20
25
  "SKILL.md"
21
26
  ],
22
27
  "scripts": {
23
- "build": "tsup src/index.ts --format cjs,esm --dts && tsup src/init.ts --format cjs --no-dts",
28
+ "build": "tsup src/index.ts src/vite.ts --format cjs,esm --dts && tsup src/init.ts --format cjs --no-dts",
24
29
  "dev": "tsup src/index.ts --format cjs,esm --dts --watch",
25
30
  "test": "tsx test/test.ts"
26
31
  },
@@ -28,7 +33,16 @@
28
33
  "serialize-error": "^13.0.1",
29
34
  "tsup": "^8.0.0",
30
35
  "tsx": "^4.7.0",
31
- "typescript": "^5.3.0"
36
+ "typescript": "^5.3.0",
37
+ "vite": "^7.3.1"
38
+ },
39
+ "peerDependencies": {
40
+ "vite": ">=5.0.0"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "vite": {
44
+ "optional": true
45
+ }
32
46
  },
33
47
  "keywords": [
34
48
  "logging",