@remote-logger/sdk 0.1.6 → 0.1.8

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/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
  ```
@@ -127,6 +132,7 @@ message String -- log content
127
132
  stack Nullable(String) -- stack trace (resolved via source maps if available)
128
133
  error_type String -- exception class name
129
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
130
136
  metadata JSON -- arbitrary structured data
131
137
  ```
132
138
 
package/dist/vite.js CHANGED
@@ -26,7 +26,10 @@ module.exports = __toCommonJS(vite_exports);
26
26
  var import_crypto = require("crypto");
27
27
  var import_fs = require("fs");
28
28
  var import_path = require("path");
29
+ var import_os = require("os");
29
30
  var DEFAULT_ENDPOINT = "https://log.terodato.com";
31
+ var RELEASE_FILE = (0, import_path.join)((0, import_os.tmpdir)(), ".remote-logger-release");
32
+ var RELEASE_FILE_MAX_AGE_MS = 5 * 60 * 1e3;
30
33
  function collectMapFiles(dir) {
31
34
  const results = [];
32
35
  try {
@@ -44,9 +47,33 @@ function collectMapFiles(dir) {
44
47
  return results;
45
48
  }
46
49
  var sharedReleaseId = null;
50
+ var uploadedOutDirs = /* @__PURE__ */ new Set();
51
+ var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
52
+ function getOrCreateReleaseId() {
53
+ if (sharedReleaseId) return sharedReleaseId;
54
+ try {
55
+ if ((0, import_fs.existsSync)(RELEASE_FILE)) {
56
+ const stat = (0, import_fs.statSync)(RELEASE_FILE);
57
+ if (Date.now() - stat.mtimeMs < RELEASE_FILE_MAX_AGE_MS) {
58
+ const id2 = (0, import_fs.readFileSync)(RELEASE_FILE, "utf-8").trim();
59
+ if (UUID_REGEX.test(id2)) {
60
+ sharedReleaseId = id2;
61
+ return id2;
62
+ }
63
+ }
64
+ }
65
+ } catch {
66
+ }
67
+ const id = (0, import_crypto.randomUUID)();
68
+ sharedReleaseId = id;
69
+ try {
70
+ (0, import_fs.writeFileSync)(RELEASE_FILE, id, "utf-8");
71
+ } catch {
72
+ }
73
+ return id;
74
+ }
47
75
  function remoteLoggerPlugin(options) {
48
- if (!sharedReleaseId) sharedReleaseId = (0, import_crypto.randomUUID)();
49
- const releaseId = sharedReleaseId;
76
+ const releaseId = getOrCreateReleaseId();
50
77
  let resolvedConfig;
51
78
  let skip = false;
52
79
  return {
@@ -69,6 +96,8 @@ function remoteLoggerPlugin(options) {
69
96
  async closeBundle() {
70
97
  if (skip) return;
71
98
  const outDir = resolvedConfig.build.outDir;
99
+ if (uploadedOutDirs.has(outDir)) return;
100
+ uploadedOutDirs.add(outDir);
72
101
  const mapFiles = collectMapFiles(outDir);
73
102
  if (mapFiles.length === 0) {
74
103
  console.log("[RemoteLogger] No source map files found, skipping upload");
package/dist/vite.mjs CHANGED
@@ -2,9 +2,12 @@ import "./chunk-JKIIIVNW.mjs";
2
2
 
3
3
  // src/vite.ts
4
4
  import { randomUUID } from "crypto";
5
- import { readdirSync, readFileSync } from "fs";
5
+ import { existsSync, readdirSync, readFileSync, statSync, writeFileSync } from "fs";
6
6
  import { join, relative } from "path";
7
+ import { tmpdir } from "os";
7
8
  var DEFAULT_ENDPOINT = "https://log.terodato.com";
9
+ var RELEASE_FILE = join(tmpdir(), ".remote-logger-release");
10
+ var RELEASE_FILE_MAX_AGE_MS = 5 * 60 * 1e3;
8
11
  function collectMapFiles(dir) {
9
12
  const results = [];
10
13
  try {
@@ -22,9 +25,33 @@ function collectMapFiles(dir) {
22
25
  return results;
23
26
  }
24
27
  var sharedReleaseId = null;
28
+ var uploadedOutDirs = /* @__PURE__ */ new Set();
29
+ var UUID_REGEX = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
30
+ function getOrCreateReleaseId() {
31
+ if (sharedReleaseId) return sharedReleaseId;
32
+ try {
33
+ if (existsSync(RELEASE_FILE)) {
34
+ const stat = statSync(RELEASE_FILE);
35
+ if (Date.now() - stat.mtimeMs < RELEASE_FILE_MAX_AGE_MS) {
36
+ const id2 = readFileSync(RELEASE_FILE, "utf-8").trim();
37
+ if (UUID_REGEX.test(id2)) {
38
+ sharedReleaseId = id2;
39
+ return id2;
40
+ }
41
+ }
42
+ }
43
+ } catch {
44
+ }
45
+ const id = randomUUID();
46
+ sharedReleaseId = id;
47
+ try {
48
+ writeFileSync(RELEASE_FILE, id, "utf-8");
49
+ } catch {
50
+ }
51
+ return id;
52
+ }
25
53
  function remoteLoggerPlugin(options) {
26
- if (!sharedReleaseId) sharedReleaseId = randomUUID();
27
- const releaseId = sharedReleaseId;
54
+ const releaseId = getOrCreateReleaseId();
28
55
  let resolvedConfig;
29
56
  let skip = false;
30
57
  return {
@@ -47,6 +74,8 @@ function remoteLoggerPlugin(options) {
47
74
  async closeBundle() {
48
75
  if (skip) return;
49
76
  const outDir = resolvedConfig.build.outDir;
77
+ if (uploadedOutDirs.has(outDir)) return;
78
+ uploadedOutDirs.add(outDir);
50
79
  const mapFiles = collectMapFiles(outDir);
51
80
  if (mapFiles.length === 0) {
52
81
  console.log("[RemoteLogger] No source map files found, skipping upload");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@remote-logger/sdk",
3
- "version": "0.1.6",
3
+ "version": "0.1.8",
4
4
  "description": "JavaScript SDK for Remote Logger",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",