@glasstrace/sdk 0.15.1 → 0.17.0

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 (78) hide show
  1. package/README.md +148 -1
  2. package/dist/adapters/drizzle.js +2 -5
  3. package/dist/adapters/drizzle.js.map +1 -1
  4. package/dist/{chunk-PD2SKFQQ.js → chunk-55FBXXER.js} +4 -8
  5. package/dist/{chunk-PD2SKFQQ.js.map → chunk-55FBXXER.js.map} +1 -1
  6. package/dist/{chunk-ZNOD6FC7.js → chunk-CTJI2YKA.js} +8 -15
  7. package/dist/{chunk-ZNOD6FC7.js.map → chunk-CTJI2YKA.js.map} +1 -1
  8. package/dist/{chunk-WK7MPK2T.js → chunk-DQ25VOKK.js} +1 -89
  9. package/dist/chunk-DQ25VOKK.js.map +1 -0
  10. package/dist/{chunk-BL3YDC6V.js → chunk-DXRZKKSO.js} +1 -6
  11. package/dist/{chunk-BL3YDC6V.js.map → chunk-DXRZKKSO.js.map} +1 -1
  12. package/dist/{chunk-2LDBR3F3.js → chunk-E33Y7BQH.js} +36 -74
  13. package/dist/chunk-E33Y7BQH.js.map +1 -0
  14. package/dist/{chunk-YMEXDDTA.js → chunk-GSGX76Q5.js} +4 -99
  15. package/dist/chunk-GSGX76Q5.js.map +1 -0
  16. package/dist/{chunk-ECEN724Y.js → chunk-J5BW7V2D.js} +4 -8
  17. package/dist/{chunk-ECEN724Y.js.map → chunk-J5BW7V2D.js.map} +1 -1
  18. package/dist/{chunk-BGZ7J74D.js → chunk-NSBPE2FW.js} +2 -16
  19. package/dist/{chunk-A2AZL6MZ.js → chunk-O63DJKIJ.js} +169 -18
  20. package/dist/chunk-O63DJKIJ.js.map +1 -0
  21. package/dist/chunk-UUUKI65I.js +851 -0
  22. package/dist/chunk-UUUKI65I.js.map +1 -0
  23. package/dist/chunk-VUZCLMIX.js +57 -0
  24. package/dist/chunk-VUZCLMIX.js.map +1 -0
  25. package/dist/{chunk-OSXIUKD5.js → chunk-WZXVS2EO.js} +1 -6
  26. package/dist/{chunk-OSXIUKD5.js.map → chunk-WZXVS2EO.js.map} +1 -1
  27. package/dist/{chunk-ROFOJQWN.js → chunk-XNDHQN4S.js} +7 -11
  28. package/dist/{chunk-ROFOJQWN.js.map → chunk-XNDHQN4S.js.map} +1 -1
  29. package/dist/cli/init.cjs +673 -161
  30. package/dist/cli/init.cjs.map +1 -1
  31. package/dist/cli/init.d.cts +54 -1
  32. package/dist/cli/init.d.ts +54 -1
  33. package/dist/cli/init.js +146 -37
  34. package/dist/cli/init.js.map +1 -1
  35. package/dist/cli/mcp-add.cjs +16 -16
  36. package/dist/cli/mcp-add.cjs.map +1 -1
  37. package/dist/cli/mcp-add.js +10 -13
  38. package/dist/cli/mcp-add.js.map +1 -1
  39. package/dist/cli/status.cjs +2 -2
  40. package/dist/cli/status.js +4 -7
  41. package/dist/cli/status.js.map +1 -1
  42. package/dist/cli/uninit.cjs +56 -59
  43. package/dist/cli/uninit.cjs.map +1 -1
  44. package/dist/cli/uninit.js +4 -4
  45. package/dist/cli/validate.cjs +2 -2
  46. package/dist/cli/validate.js +3 -6
  47. package/dist/cli/validate.js.map +1 -1
  48. package/dist/{esm-MDK7CZID.js → esm-KBPHCVB4.js} +3 -3
  49. package/dist/{getMachineId-bsd-4NIRBWME.js → getMachineId-bsd-345PYXFX.js} +4 -7
  50. package/dist/{getMachineId-bsd-4NIRBWME.js.map → getMachineId-bsd-345PYXFX.js.map} +1 -1
  51. package/dist/{getMachineId-darwin-2XNOCCJQ.js → getMachineId-darwin-5L2D25AD.js} +4 -7
  52. package/dist/{getMachineId-darwin-2XNOCCJQ.js.map → getMachineId-darwin-5L2D25AD.js.map} +1 -1
  53. package/dist/{getMachineId-linux-V6YSQEY7.js → getMachineId-linux-KJR4P5HN.js} +3 -6
  54. package/dist/{getMachineId-linux-V6YSQEY7.js.map → getMachineId-linux-KJR4P5HN.js.map} +1 -1
  55. package/dist/{getMachineId-unsupported-4FKBJNVO.js → getMachineId-unsupported-NDNXDYDY.js} +3 -6
  56. package/dist/{getMachineId-unsupported-4FKBJNVO.js.map → getMachineId-unsupported-NDNXDYDY.js.map} +1 -1
  57. package/dist/{getMachineId-win-WLRZBKVG.js → getMachineId-win-T7PJNJXG.js} +4 -7
  58. package/dist/{getMachineId-win-WLRZBKVG.js.map → getMachineId-win-T7PJNJXG.js.map} +1 -1
  59. package/dist/index.cjs +565 -463
  60. package/dist/index.cjs.map +1 -1
  61. package/dist/index.d.cts +93 -4
  62. package/dist/index.d.ts +93 -4
  63. package/dist/index.js +286 -702
  64. package/dist/index.js.map +1 -1
  65. package/dist/{monorepo-YILKGQXQ.js → monorepo-N5Z63XP7.js} +4 -4
  66. package/dist/{source-map-uploader-3GWUQDTS.js → source-map-uploader-26QPRSCG.js} +5 -4
  67. package/dist/source-map-uploader-26QPRSCG.js.map +1 -0
  68. package/package.json +1 -1
  69. package/dist/chunk-2LDBR3F3.js.map +0 -1
  70. package/dist/chunk-A2AZL6MZ.js.map +0 -1
  71. package/dist/chunk-BGZ7J74D.js.map +0 -1
  72. package/dist/chunk-UPS5BGER.js +0 -182
  73. package/dist/chunk-UPS5BGER.js.map +0 -1
  74. package/dist/chunk-WK7MPK2T.js.map +0 -1
  75. package/dist/chunk-YMEXDDTA.js.map +0 -1
  76. /package/dist/{esm-MDK7CZID.js.map → chunk-NSBPE2FW.js.map} +0 -0
  77. /package/dist/{monorepo-YILKGQXQ.js.map → esm-KBPHCVB4.js.map} +0 -0
  78. /package/dist/{source-map-uploader-3GWUQDTS.js.map → monorepo-N5Z63XP7.js.map} +0 -0
package/dist/index.js CHANGED
@@ -4,32 +4,45 @@ import {
4
4
  computeBuildHash,
5
5
  discoverSourceMapFiles,
6
6
  installConsoleCapture,
7
- isAnonymousMode,
8
- isProductionDisabled,
9
7
  maybeShowMcpNudge,
10
- readEnvVars,
11
- resolveConfig,
8
+ maybeShowServerActionNudge,
12
9
  sdkLog,
13
10
  uploadSourceMaps,
14
11
  uploadSourceMapsAuto,
15
12
  uploadSourceMapsPresigned
16
- } from "./chunk-2LDBR3F3.js";
13
+ } from "./chunk-E33Y7BQH.js";
17
14
  import {
15
+ _setCurrentConfig,
18
16
  buildImportGraph,
17
+ collectHealthReport,
18
+ consumeRateLimitFlag,
19
+ didLastInitSucceed,
19
20
  discoverTestFiles,
20
- extractImports
21
- } from "./chunk-UPS5BGER.js";
21
+ extractImports,
22
+ getActiveConfig,
23
+ getClaimResult,
24
+ getLinkedAccountId,
25
+ loadCachedConfig,
26
+ performInit,
27
+ recordSpansDropped,
28
+ recordSpansExported,
29
+ saveCachedConfig,
30
+ sendInitRequest
31
+ } from "./chunk-UUUKI65I.js";
32
+ import {
33
+ isAnonymousMode,
34
+ isProductionDisabled,
35
+ readEnvVars,
36
+ resolveConfig
37
+ } from "./chunk-VUZCLMIX.js";
22
38
  import {
23
39
  getOrCreateAnonKey,
24
40
  readAnonKey
25
- } from "./chunk-ECEN724Y.js";
41
+ } from "./chunk-J5BW7V2D.js";
26
42
  import {
27
- DEFAULT_CAPTURE_CONFIG,
28
43
  GLASSTRACE_ATTRIBUTE_NAMES,
29
- SdkCachedConfigSchema,
30
- SdkInitResponseSchema,
31
44
  SessionIdSchema
32
- } from "./chunk-YMEXDDTA.js";
45
+ } from "./chunk-GSGX76Q5.js";
33
46
  import {
34
47
  DiagLogLevel,
35
48
  INVALID_SPAN_CONTEXT,
@@ -46,17 +59,12 @@ import {
46
59
  isSpanContextValid,
47
60
  isValidTraceId,
48
61
  trace
49
- } from "./chunk-WK7MPK2T.js";
62
+ } from "./chunk-DQ25VOKK.js";
50
63
  import {
51
- __require,
52
- init_esm_shims
53
- } from "./chunk-BGZ7J74D.js";
54
-
55
- // src/index.ts
56
- init_esm_shims();
64
+ __require
65
+ } from "./chunk-NSBPE2FW.js";
57
66
 
58
67
  // src/errors.ts
59
- init_esm_shims();
60
68
  var SdkError = class extends Error {
61
69
  code;
62
70
  constructor(code, message, cause) {
@@ -67,7 +75,6 @@ var SdkError = class extends Error {
67
75
  };
68
76
 
69
77
  // src/session.ts
70
- init_esm_shims();
71
78
  var FOUR_HOURS_MS = 4 * 60 * 60 * 1e3;
72
79
  var hashFn = null;
73
80
  function fnv1aHash(input) {
@@ -82,7 +89,7 @@ function fnv1aHash(input) {
82
89
  function getHashFn() {
83
90
  if (hashFn) return hashFn;
84
91
  try {
85
- const { createHash } = __require("crypto");
92
+ const { createHash } = __require("node:crypto");
86
93
  hashFn = (input) => createHash("sha256").update(input).digest("hex").slice(0, 16);
87
94
  } catch {
88
95
  hashFn = (input) => {
@@ -158,7 +165,6 @@ var SessionManager = class {
158
165
  };
159
166
 
160
167
  // src/fetch-classifier.ts
161
- init_esm_shims();
162
168
  var cachedPort2 = process.env.PORT ?? "3000";
163
169
  function classifyFetchTarget(url) {
164
170
  let parsed;
@@ -183,395 +189,7 @@ function classifyFetchTarget(url) {
183
189
  return "unknown";
184
190
  }
185
191
 
186
- // src/init-client.ts
187
- init_esm_shims();
188
-
189
- // src/health-collector.ts
190
- init_esm_shims();
191
- var tracesExported = 0;
192
- var tracesDropped = 0;
193
- var initFailures = 0;
194
- var lastConfigSyncAt = null;
195
- function recordSpansExported(count) {
196
- if (!Number.isFinite(count) || count < 0 || !Number.isInteger(count)) return;
197
- tracesExported += count;
198
- }
199
- function recordSpansDropped(count) {
200
- if (!Number.isFinite(count) || count < 0 || !Number.isInteger(count)) return;
201
- tracesDropped += count;
202
- }
203
- function recordInitFailure() {
204
- try {
205
- initFailures += 1;
206
- } catch {
207
- }
208
- }
209
- function recordConfigSync(timestamp) {
210
- try {
211
- lastConfigSyncAt = timestamp;
212
- } catch {
213
- }
214
- }
215
- function collectHealthReport(sdkVersion) {
216
- try {
217
- const now = Date.now();
218
- const configAge = lastConfigSyncAt !== null ? Math.max(0, now - lastConfigSyncAt) : 0;
219
- return {
220
- tracesExportedSinceLastInit: tracesExported,
221
- tracesDropped,
222
- initFailures,
223
- configAge: Math.round(configAge),
224
- sdkVersion
225
- };
226
- } catch {
227
- return null;
228
- }
229
- }
230
- function acknowledgeHealthReport(report) {
231
- const exp = Math.max(0, report.tracesExportedSinceLastInit);
232
- const expVal = tracesExported - exp;
233
- tracesExported = Number.isFinite(expVal) ? Math.max(0, expVal) : tracesExported;
234
- const drop = Math.max(0, report.tracesDropped);
235
- const dropVal = tracesDropped - drop;
236
- tracesDropped = Number.isFinite(dropVal) ? Math.max(0, dropVal) : tracesDropped;
237
- const fail = Math.max(0, report.initFailures);
238
- const failVal = initFailures - fail;
239
- initFailures = Number.isFinite(failVal) ? Math.max(0, failVal) : initFailures;
240
- }
241
-
242
- // src/init-client.ts
243
- var GLASSTRACE_DIR = ".glasstrace";
244
- var CONFIG_FILE = "config";
245
- var TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1e3;
246
- var INIT_TIMEOUT_MS = 1e4;
247
- var fsPathAsyncCache;
248
- async function loadFsPathAsync() {
249
- if (fsPathAsyncCache !== void 0) return fsPathAsyncCache;
250
- try {
251
- const [fs2, path2] = await Promise.all([
252
- import("fs/promises"),
253
- import("path")
254
- ]);
255
- fsPathAsyncCache = { fs: fs2, path: path2 };
256
- return fsPathAsyncCache;
257
- } catch {
258
- fsPathAsyncCache = null;
259
- return null;
260
- }
261
- }
262
- function loadFsSyncOrNull() {
263
- try {
264
- const fs2 = __require("fs");
265
- const path2 = __require("path");
266
- return { readFileSync: fs2.readFileSync, join: path2.join };
267
- } catch {
268
- return null;
269
- }
270
- }
271
- var currentConfig = null;
272
- var configCacheChecked = false;
273
- var rateLimitBackoff = false;
274
- var lastInitSucceeded = false;
275
- function loadCachedConfig(projectRoot) {
276
- const modules = loadFsSyncOrNull();
277
- if (!modules) return null;
278
- const root = projectRoot ?? process.cwd();
279
- const configPath = modules.join(root, GLASSTRACE_DIR, CONFIG_FILE);
280
- try {
281
- const content = modules.readFileSync(configPath, "utf-8");
282
- const parsed = JSON.parse(content);
283
- const cached = SdkCachedConfigSchema.parse(parsed);
284
- const age = Date.now() - cached.cachedAt;
285
- if (age > TWENTY_FOUR_HOURS_MS) {
286
- console.warn(
287
- `[glasstrace] Cached config is ${Math.round(age / 36e5)}h old. Will refresh on next init.`
288
- );
289
- }
290
- const result = SdkInitResponseSchema.safeParse(cached.response);
291
- if (result.success) {
292
- recordConfigSync(cached.cachedAt);
293
- return result.data;
294
- }
295
- console.warn("[glasstrace] Cached config failed validation. Using defaults.");
296
- return null;
297
- } catch {
298
- return null;
299
- }
300
- }
301
- async function saveCachedConfig(response, projectRoot) {
302
- const modules = await loadFsPathAsync();
303
- if (!modules) return;
304
- const root = projectRoot ?? process.cwd();
305
- const dirPath = modules.path.join(root, GLASSTRACE_DIR);
306
- const configPath = modules.path.join(dirPath, CONFIG_FILE);
307
- const tmpPath = `${configPath}.tmp`;
308
- try {
309
- await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
310
- await modules.fs.chmod(dirPath, 448);
311
- const cached = {
312
- response,
313
- cachedAt: Date.now()
314
- };
315
- await modules.fs.writeFile(tmpPath, JSON.stringify(cached), {
316
- encoding: "utf-8",
317
- mode: 384
318
- });
319
- try {
320
- await modules.fs.chmod(tmpPath, 384);
321
- await modules.fs.rename(tmpPath, configPath);
322
- } catch (renameErr) {
323
- try {
324
- await modules.fs.unlink(tmpPath);
325
- } catch {
326
- }
327
- throw renameErr;
328
- }
329
- await modules.fs.chmod(configPath, 384);
330
- } catch (err) {
331
- console.warn(
332
- `[glasstrace] Failed to cache config to ${configPath}: ${err instanceof Error ? err.message : String(err)}`
333
- );
334
- }
335
- }
336
- async function sendInitRequest(config, anonKey, sdkVersion, importGraph, healthReport, diagnostics, signal) {
337
- const effectiveKey = config.apiKey || anonKey;
338
- if (!effectiveKey) {
339
- throw new Error("No API key available for init request");
340
- }
341
- const payload = {
342
- sdkVersion
343
- };
344
- if (config.apiKey && anonKey) {
345
- payload.anonKey = anonKey;
346
- }
347
- if (config.environment) {
348
- payload.environment = config.environment;
349
- }
350
- if (importGraph) {
351
- payload.importGraph = importGraph;
352
- }
353
- if (healthReport) {
354
- payload.healthReport = healthReport;
355
- }
356
- if (diagnostics) {
357
- payload.diagnostics = diagnostics;
358
- }
359
- const url = `${config.endpoint}/v1/sdk/init`;
360
- const response = await fetch(url, {
361
- method: "POST",
362
- headers: {
363
- "Content-Type": "application/json",
364
- Authorization: `Bearer ${effectiveKey}`
365
- },
366
- body: JSON.stringify(payload),
367
- signal
368
- });
369
- if (!response.ok) {
370
- try {
371
- await response.text();
372
- } catch {
373
- }
374
- const error = new Error(`Init request failed with status ${response.status}`);
375
- error.status = response.status;
376
- throw error;
377
- }
378
- const body = await response.json();
379
- return SdkInitResponseSchema.parse(body);
380
- }
381
- async function writeClaimedKey(newApiKey, projectRoot) {
382
- const modules = await loadFsPathAsync();
383
- if (modules) {
384
- const root = projectRoot ?? process.cwd();
385
- const envLocalPath = modules.path.join(root, ".env.local");
386
- let envLocalWritten = false;
387
- try {
388
- let content;
389
- try {
390
- content = await modules.fs.readFile(envLocalPath, "utf-8");
391
- if (/^GLASSTRACE_API_KEY=.*/m.test(content)) {
392
- content = content.replace(
393
- /^GLASSTRACE_API_KEY=.*$/gm,
394
- `GLASSTRACE_API_KEY=${newApiKey}`
395
- );
396
- } else {
397
- if (content.length > 0 && !content.endsWith("\n")) {
398
- content += "\n";
399
- }
400
- content += `GLASSTRACE_API_KEY=${newApiKey}
401
- `;
402
- }
403
- } catch (readErr) {
404
- const code = readErr instanceof Error ? readErr.code : void 0;
405
- if (code !== "ENOENT") {
406
- throw readErr;
407
- }
408
- content = `GLASSTRACE_API_KEY=${newApiKey}
409
- `;
410
- }
411
- await modules.fs.writeFile(envLocalPath, content, { encoding: "utf-8", mode: 384 });
412
- await modules.fs.chmod(envLocalPath, 384);
413
- envLocalWritten = true;
414
- } catch {
415
- }
416
- if (envLocalWritten) {
417
- try {
418
- process.stderr.write(
419
- "[glasstrace] Account claimed! API key written to .env.local. Restart your dev server to use it.\n"
420
- );
421
- } catch {
422
- }
423
- return;
424
- }
425
- let claimedKeyWritten = false;
426
- try {
427
- const dirPath = modules.path.join(root, GLASSTRACE_DIR);
428
- await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
429
- await modules.fs.chmod(dirPath, 448);
430
- const claimedKeyPath = modules.path.join(dirPath, "claimed-key");
431
- await modules.fs.writeFile(claimedKeyPath, newApiKey, {
432
- encoding: "utf-8",
433
- mode: 384
434
- });
435
- await modules.fs.chmod(claimedKeyPath, 384);
436
- claimedKeyWritten = true;
437
- } catch {
438
- }
439
- if (claimedKeyWritten) {
440
- try {
441
- process.stderr.write(
442
- "[glasstrace] Account claimed! API key written to .glasstrace/claimed-key. Copy it to your .env.local file.\n"
443
- );
444
- } catch {
445
- }
446
- return;
447
- }
448
- }
449
- try {
450
- process.stderr.write(
451
- "[glasstrace] Account claimed but could not write key to disk. Visit your dashboard settings to rotate and retrieve a new API key.\n"
452
- );
453
- } catch {
454
- }
455
- }
456
- async function performInit(config, anonKey, sdkVersion, healthReport) {
457
- lastInitSucceeded = false;
458
- if (rateLimitBackoff) {
459
- rateLimitBackoff = false;
460
- return null;
461
- }
462
- try {
463
- const effectiveKey = config.apiKey || anonKey;
464
- if (!effectiveKey) {
465
- console.warn("[glasstrace] No API key available for init request.");
466
- return null;
467
- }
468
- const controller = new AbortController();
469
- const timeoutId = setTimeout(() => controller.abort(), INIT_TIMEOUT_MS);
470
- try {
471
- const result = await sendInitRequest(
472
- config,
473
- anonKey,
474
- sdkVersion,
475
- void 0,
476
- healthReport ?? void 0,
477
- void 0,
478
- controller.signal
479
- );
480
- clearTimeout(timeoutId);
481
- currentConfig = result;
482
- recordConfigSync(Date.now());
483
- if (healthReport) {
484
- acknowledgeHealthReport(healthReport);
485
- }
486
- lastInitSucceeded = true;
487
- await saveCachedConfig(result);
488
- if (result.claimResult) {
489
- try {
490
- await writeClaimedKey(result.claimResult.newApiKey);
491
- } catch {
492
- }
493
- return { claimResult: result.claimResult };
494
- }
495
- return null;
496
- } catch (err) {
497
- clearTimeout(timeoutId);
498
- recordInitFailure();
499
- if (err instanceof DOMException && err.name === "AbortError") {
500
- console.warn("[glasstrace] ingestion_unreachable: Init request timed out.");
501
- return null;
502
- }
503
- const status = err.status;
504
- if (status === 401) {
505
- console.warn(
506
- "[glasstrace] ingestion_auth_failed: Check your GLASSTRACE_API_KEY."
507
- );
508
- return null;
509
- }
510
- if (status === 429) {
511
- console.warn("[glasstrace] ingestion_rate_limited: Backing off.");
512
- rateLimitBackoff = true;
513
- return null;
514
- }
515
- if (typeof status === "number" && status >= 400) {
516
- console.warn(
517
- `[glasstrace] Init request failed with status ${status}. Using cached config.`
518
- );
519
- return null;
520
- }
521
- if (err instanceof Error && err.name === "ZodError") {
522
- console.warn(
523
- "[glasstrace] Init response failed validation (schema version mismatch?). Using cached config."
524
- );
525
- return null;
526
- }
527
- console.warn(
528
- `[glasstrace] ingestion_unreachable: ${err instanceof Error ? err.message : String(err)}`
529
- );
530
- return null;
531
- }
532
- } catch (err) {
533
- console.warn(
534
- `[glasstrace] Unexpected init error: ${err instanceof Error ? err.message : String(err)}`
535
- );
536
- }
537
- return null;
538
- }
539
- function getActiveConfig() {
540
- if (currentConfig) {
541
- return currentConfig.config;
542
- }
543
- if (!configCacheChecked) {
544
- configCacheChecked = true;
545
- const cached = loadCachedConfig();
546
- if (cached) {
547
- currentConfig = cached;
548
- return cached.config;
549
- }
550
- }
551
- return { ...DEFAULT_CAPTURE_CONFIG };
552
- }
553
- function getLinkedAccountId() {
554
- return currentConfig?.linkedAccountId;
555
- }
556
- function getClaimResult() {
557
- return currentConfig?.claimResult;
558
- }
559
- function _setCurrentConfig(config) {
560
- currentConfig = config;
561
- }
562
- function consumeRateLimitFlag() {
563
- if (rateLimitBackoff) {
564
- rateLimitBackoff = false;
565
- return true;
566
- }
567
- return false;
568
- }
569
- function didLastInitSucceed() {
570
- return lastInitSucceeded;
571
- }
572
-
573
192
  // src/span-processor.ts
574
- init_esm_shims();
575
193
  var GlasstraceSpanProcessor = class {
576
194
  wrappedProcessor;
577
195
  /* eslint-disable @typescript-eslint/no-unused-vars -- backward compat signature */
@@ -593,7 +211,6 @@ var GlasstraceSpanProcessor = class {
593
211
  };
594
212
 
595
213
  // src/enriching-exporter.ts
596
- init_esm_shims();
597
214
  var ATTR = GLASSTRACE_ATTRIBUTE_NAMES;
598
215
  var API_KEY_PENDING = "pending";
599
216
  var MAX_PENDING_SPANS = 1024;
@@ -712,7 +329,8 @@ var GlasstraceExporter = class {
712
329
  if (typeof existingCid === "string") {
713
330
  extra[ATTR.CORRELATION_ID] = existingCid;
714
331
  }
715
- const route = attrs["http.route"] ?? name;
332
+ const rawRoute = attrs["http.route"];
333
+ const route = typeof rawRoute === "string" ? rawRoute : name;
716
334
  if (route) {
717
335
  extra[ATTR.ROUTE] = route;
718
336
  }
@@ -736,6 +354,17 @@ var GlasstraceExporter = class {
736
354
  if (method) {
737
355
  extra[ATTR.HTTP_METHOD] = method;
738
356
  }
357
+ const actionRoute = extractLeadingPath(route);
358
+ if (method === "POST" && actionRoute) {
359
+ const isApiRoute = actionRoute === "/api" || actionRoute.startsWith("/api/");
360
+ const isInternalRoute = actionRoute.startsWith("/_next/");
361
+ if (!isApiRoute && !isInternalRoute) {
362
+ extra[ATTR.NEXT_ACTION_DETECTED] = true;
363
+ if (typeof extra[ATTR.CORRELATION_ID] !== "string") {
364
+ maybeShowServerActionNudge();
365
+ }
366
+ }
367
+ }
739
368
  const statusCode = attrs["http.status_code"] ?? attrs["http.response.status_code"];
740
369
  if (statusCode !== void 0) {
741
370
  extra[ATTR.HTTP_STATUS_CODE] = statusCode;
@@ -944,6 +573,21 @@ function getExceptionEventDetails(span) {
944
573
  message: typeof message === "string" ? message : void 0
945
574
  };
946
575
  }
576
+ function extractLeadingPath(raw) {
577
+ if (!raw) return void 0;
578
+ const trimmed = raw.trim();
579
+ if (trimmed.length === 0) return void 0;
580
+ if (trimmed.startsWith("/")) {
581
+ const firstSpace = trimmed.indexOf(" ");
582
+ return firstSpace === -1 ? trimmed : trimmed.slice(0, firstSpace);
583
+ }
584
+ for (const token of trimmed.split(/\s+/)) {
585
+ if (token.startsWith("/")) {
586
+ return token;
587
+ }
588
+ }
589
+ return void 0;
590
+ }
947
591
  function deriveOrmProvider(instrumentationName) {
948
592
  const lower = instrumentationName.toLowerCase();
949
593
  if (lower.includes("prisma")) {
@@ -972,7 +616,6 @@ function deriveErrorCategory(errorType) {
972
616
  }
973
617
 
974
618
  // src/discovery-endpoint.ts
975
- init_esm_shims();
976
619
  function isAllowedOrigin(origin) {
977
620
  if (origin === null) return true;
978
621
  if (origin.startsWith("chrome-extension://")) return true;
@@ -1061,29 +704,7 @@ function createDiscoveryHandler(getAnonKey, getSessionId, getClaimState) {
1061
704
  };
1062
705
  }
1063
706
 
1064
- // src/register.ts
1065
- init_esm_shims();
1066
-
1067
- // src/otel-config.ts
1068
- init_esm_shims();
1069
-
1070
- // ../../node_modules/@opentelemetry/exporter-trace-otlp-http/build/esm/index.js
1071
- init_esm_shims();
1072
-
1073
- // ../../node_modules/@opentelemetry/exporter-trace-otlp-http/build/esm/platform/index.js
1074
- init_esm_shims();
1075
-
1076
- // ../../node_modules/@opentelemetry/exporter-trace-otlp-http/build/esm/platform/node/index.js
1077
- init_esm_shims();
1078
-
1079
- // ../../node_modules/@opentelemetry/exporter-trace-otlp-http/build/esm/platform/node/OTLPTraceExporter.js
1080
- init_esm_shims();
1081
-
1082
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/index.js
1083
- init_esm_shims();
1084
-
1085
707
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/OTLPExporterBase.js
1086
- init_esm_shims();
1087
708
  var OTLPExporterBase = class {
1088
709
  _delegate;
1089
710
  constructor(delegate) {
@@ -1106,7 +727,6 @@ var OTLPExporterBase = class {
1106
727
  };
1107
728
 
1108
729
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/types.js
1109
- init_esm_shims();
1110
730
  var OTLPExporterError = class extends Error {
1111
731
  code;
1112
732
  name = "OTLPExporterError";
@@ -1119,7 +739,6 @@ var OTLPExporterError = class extends Error {
1119
739
  };
1120
740
 
1121
741
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/shared-configuration.js
1122
- init_esm_shims();
1123
742
  function validateTimeoutMillis(timeoutMillis) {
1124
743
  if (Number.isFinite(timeoutMillis) && timeoutMillis > 0) {
1125
744
  return timeoutMillis;
@@ -1148,7 +767,6 @@ function getSharedConfigurationDefaults() {
1148
767
  }
1149
768
 
1150
769
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/bounded-queue-export-promise-handler.js
1151
- init_esm_shims();
1152
770
  var BoundedQueueExportPromiseHandler = class {
1153
771
  _concurrencyLimit;
1154
772
  _sendingPromises = [];
@@ -1180,14 +798,7 @@ function createBoundedQueueExportPromiseHandler(options) {
1180
798
  return new BoundedQueueExportPromiseHandler(options.concurrencyLimit);
1181
799
  }
1182
800
 
1183
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/otlp-export-delegate.js
1184
- init_esm_shims();
1185
-
1186
- // ../../node_modules/@opentelemetry/core/build/esm/index.js
1187
- init_esm_shims();
1188
-
1189
801
  // ../../node_modules/@opentelemetry/core/build/esm/trace/suppress-tracing.js
1190
- init_esm_shims();
1191
802
  var SUPPRESS_TRACING_KEY = createContextKey("OpenTelemetry SDK Context Key SUPPRESS_TRACING");
1192
803
  function suppressTracing(context2) {
1193
804
  return context2.setValue(SUPPRESS_TRACING_KEY, true);
@@ -1197,13 +808,11 @@ function isTracingSuppressed(context2) {
1197
808
  }
1198
809
 
1199
810
  // ../../node_modules/@opentelemetry/core/build/esm/baggage/constants.js
1200
- init_esm_shims();
1201
811
  var BAGGAGE_KEY_PAIR_SEPARATOR = "=";
1202
812
  var BAGGAGE_PROPERTIES_SEPARATOR = ";";
1203
813
  var BAGGAGE_ITEMS_SEPARATOR = ",";
1204
814
 
1205
815
  // ../../node_modules/@opentelemetry/core/build/esm/baggage/utils.js
1206
- init_esm_shims();
1207
816
  function parsePairKeyValue(entry) {
1208
817
  if (!entry)
1209
818
  return;
@@ -1245,7 +854,6 @@ function parseKeyPairsIntoRecord(value) {
1245
854
  }
1246
855
 
1247
856
  // ../../node_modules/@opentelemetry/core/build/esm/common/attributes.js
1248
- init_esm_shims();
1249
857
  function sanitizeAttributes(attributes) {
1250
858
  const out = {};
1251
859
  if (typeof attributes !== "object" || attributes == null) {
@@ -1314,11 +922,7 @@ function isValidPrimitiveAttributeValueType(valType) {
1314
922
  return false;
1315
923
  }
1316
924
 
1317
- // ../../node_modules/@opentelemetry/core/build/esm/common/global-error-handler.js
1318
- init_esm_shims();
1319
-
1320
925
  // ../../node_modules/@opentelemetry/core/build/esm/common/logging-error-handler.js
1321
- init_esm_shims();
1322
926
  function loggingErrorHandler() {
1323
927
  return (ex) => {
1324
928
  diag.error(stringifyException(ex));
@@ -1357,17 +961,7 @@ function globalErrorHandler(ex) {
1357
961
  }
1358
962
  }
1359
963
 
1360
- // ../../node_modules/@opentelemetry/core/build/esm/common/time.js
1361
- init_esm_shims();
1362
-
1363
- // ../../node_modules/@opentelemetry/core/build/esm/platform/index.js
1364
- init_esm_shims();
1365
-
1366
- // ../../node_modules/@opentelemetry/core/build/esm/platform/node/index.js
1367
- init_esm_shims();
1368
-
1369
964
  // ../../node_modules/@opentelemetry/core/build/esm/platform/node/environment.js
1370
- init_esm_shims();
1371
965
  import { inspect } from "util";
1372
966
  function getNumberFromEnv(key) {
1373
967
  const raw = process.env[key];
@@ -1389,15 +983,10 @@ function getStringFromEnv(key) {
1389
983
  return raw;
1390
984
  }
1391
985
 
1392
- // ../../node_modules/@opentelemetry/core/build/esm/platform/node/sdk-info.js
1393
- init_esm_shims();
1394
-
1395
986
  // ../../node_modules/@opentelemetry/core/build/esm/version.js
1396
- init_esm_shims();
1397
987
  var VERSION = "2.6.1";
1398
988
 
1399
989
  // ../../node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js
1400
- init_esm_shims();
1401
990
  var ATTR_EXCEPTION_MESSAGE = "exception.message";
1402
991
  var ATTR_EXCEPTION_STACKTRACE = "exception.stacktrace";
1403
992
  var ATTR_EXCEPTION_TYPE = "exception.type";
@@ -1408,7 +997,6 @@ var ATTR_TELEMETRY_SDK_NAME = "telemetry.sdk.name";
1408
997
  var ATTR_TELEMETRY_SDK_VERSION = "telemetry.sdk.version";
1409
998
 
1410
999
  // ../../node_modules/@opentelemetry/core/build/esm/semconv.js
1411
- init_esm_shims();
1412
1000
  var ATTR_PROCESS_RUNTIME_NAME = "process.runtime.name";
1413
1001
 
1414
1002
  // ../../node_modules/@opentelemetry/core/build/esm/platform/node/sdk-info.js
@@ -1466,18 +1054,13 @@ function addHrTimes(time1, time2) {
1466
1054
  }
1467
1055
 
1468
1056
  // ../../node_modules/@opentelemetry/core/build/esm/ExportResult.js
1469
- init_esm_shims();
1470
1057
  var ExportResultCode;
1471
1058
  (function(ExportResultCode2) {
1472
1059
  ExportResultCode2[ExportResultCode2["SUCCESS"] = 0] = "SUCCESS";
1473
1060
  ExportResultCode2[ExportResultCode2["FAILED"] = 1] = "FAILED";
1474
1061
  })(ExportResultCode || (ExportResultCode = {}));
1475
1062
 
1476
- // ../../node_modules/@opentelemetry/core/build/esm/utils/merge.js
1477
- init_esm_shims();
1478
-
1479
1063
  // ../../node_modules/@opentelemetry/core/build/esm/utils/lodash.merge.js
1480
- init_esm_shims();
1481
1064
  var objectTag = "[object Object]";
1482
1065
  var nullTag = "[object Null]";
1483
1066
  var undefinedTag = "[object Undefined]";
@@ -1637,11 +1220,7 @@ function shouldMerge(one, two) {
1637
1220
  return true;
1638
1221
  }
1639
1222
 
1640
- // ../../node_modules/@opentelemetry/core/build/esm/utils/callback.js
1641
- init_esm_shims();
1642
-
1643
1223
  // ../../node_modules/@opentelemetry/core/build/esm/utils/promise.js
1644
- init_esm_shims();
1645
1224
  var Deferred = class {
1646
1225
  _promise;
1647
1226
  _resolve;
@@ -1693,7 +1272,6 @@ var BindOnceFuture = class {
1693
1272
  };
1694
1273
 
1695
1274
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/logging-response-handler.js
1696
- init_esm_shims();
1697
1275
  function isPartialSuccessResponse(response) {
1698
1276
  return Object.prototype.hasOwnProperty.call(response, "partialSuccess");
1699
1277
  }
@@ -1791,11 +1369,7 @@ function createOtlpExportDelegate(components, settings) {
1791
1369
  return new OTLPExportDelegate(components.transport, components.serializer, createLoggingPartialSuccessResponseHandler(), components.promiseHandler, settings.timeout);
1792
1370
  }
1793
1371
 
1794
- // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/index.js
1795
- init_esm_shims();
1796
-
1797
1372
  // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/common/internal.js
1798
- init_esm_shims();
1799
1373
  function createResource(resource, encoder) {
1800
1374
  const result = {
1801
1375
  attributes: toAttributes(resource.attributes, encoder),
@@ -1856,7 +1430,6 @@ function toAnyValue(value, encoder) {
1856
1430
  }
1857
1431
 
1858
1432
  // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/common/utils.js
1859
- init_esm_shims();
1860
1433
  function hrTimeToNanos(hrTime2) {
1861
1434
  const NANOSECONDS = BigInt(1e9);
1862
1435
  return BigInt(Math.trunc(hrTime2[0])) * NANOSECONDS + BigInt(Math.trunc(hrTime2[1]));
@@ -1885,14 +1458,7 @@ var JSON_ENCODER = {
1885
1458
  }
1886
1459
  };
1887
1460
 
1888
- // ../../node_modules/@opentelemetry/resources/build/esm/index.js
1889
- init_esm_shims();
1890
-
1891
- // ../../node_modules/@opentelemetry/resources/build/esm/ResourceImpl.js
1892
- init_esm_shims();
1893
-
1894
1461
  // ../../node_modules/@opentelemetry/resources/build/esm/default-service-name.js
1895
- init_esm_shims();
1896
1462
  var serviceName;
1897
1463
  function defaultServiceName() {
1898
1464
  if (serviceName === void 0) {
@@ -1907,7 +1473,6 @@ function defaultServiceName() {
1907
1473
  }
1908
1474
 
1909
1475
  // ../../node_modules/@opentelemetry/resources/build/esm/utils.js
1910
- init_esm_shims();
1911
1476
  var isPromiseLike = (val) => {
1912
1477
  return val !== null && typeof val === "object" && typeof val.then === "function";
1913
1478
  };
@@ -2035,7 +1600,6 @@ function mergeSchemaUrl(old, updating) {
2035
1600
  }
2036
1601
 
2037
1602
  // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/trace/internal.js
2038
- init_esm_shims();
2039
1603
  var SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 256;
2040
1604
  var SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 512;
2041
1605
  function buildSpanFlagsFrom(traceFlags, isRemote) {
@@ -2148,11 +1712,7 @@ function spanRecordsToResourceSpans(readableSpans, encoder) {
2148
1712
  return out;
2149
1713
  }
2150
1714
 
2151
- // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/trace/json/index.js
2152
- init_esm_shims();
2153
-
2154
1715
  // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/trace/json/trace.js
2155
- init_esm_shims();
2156
1716
  var JsonTraceSerializer = {
2157
1717
  serializeRequest: (arg) => {
2158
1718
  const request = createExportTraceServiceRequest(arg, JSON_ENCODER);
@@ -2168,17 +1728,7 @@ var JsonTraceSerializer = {
2168
1728
  }
2169
1729
  };
2170
1730
 
2171
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/index-node-http.js
2172
- init_esm_shims();
2173
-
2174
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/otlp-node-http-configuration.js
2175
- init_esm_shims();
2176
-
2177
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/otlp-http-configuration.js
2178
- init_esm_shims();
2179
-
2180
1731
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/util.js
2181
- init_esm_shims();
2182
1732
  function validateAndNormalizeHeaders(partialHeaders) {
2183
1733
  const headers = {};
2184
1734
  Object.entries(partialHeaders ?? {}).forEach(([key, value]) => {
@@ -2260,19 +1810,11 @@ function getNodeHttpConfigurationDefaults(requiredHeaders, signalResourcePath) {
2260
1810
  };
2261
1811
  }
2262
1812
 
2263
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/otlp-http-export-delegate.js
2264
- init_esm_shims();
2265
-
2266
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/transport/http-exporter-transport.js
2267
- init_esm_shims();
2268
-
2269
1813
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/transport/http-transport-utils.js
2270
- init_esm_shims();
2271
1814
  import * as zlib from "zlib";
2272
1815
  import { Readable } from "stream";
2273
1816
 
2274
1817
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/is-export-retryable.js
2275
- init_esm_shims();
2276
1818
  function isExportHTTPErrorRetryable(statusCode) {
2277
1819
  return statusCode === 429 || statusCode === 502 || statusCode === 503 || statusCode === 504;
2278
1820
  }
@@ -2292,7 +1834,6 @@ function parseRetryAfterToMills(retryAfter) {
2292
1834
  }
2293
1835
 
2294
1836
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/version.js
2295
- init_esm_shims();
2296
1837
  var VERSION2 = "0.214.0";
2297
1838
 
2298
1839
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/transport/http-transport-utils.js
@@ -2450,7 +1991,6 @@ function createHttpExporterTransport(parameters) {
2450
1991
  }
2451
1992
 
2452
1993
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/retrying-transport.js
2453
- init_esm_shims();
2454
1994
  var MAX_ATTEMPTS = 5;
2455
1995
  var INITIAL_BACKOFF = 1e3;
2456
1996
  var MAX_BACKOFF = 5e3;
@@ -2518,7 +2058,6 @@ function createOtlpHttpExportDelegate(options, serializer) {
2518
2058
  }
2519
2059
 
2520
2060
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/shared-env-configuration.js
2521
- init_esm_shims();
2522
2061
  function parseAndValidateTimeoutFromEnv(timeoutEnvVar) {
2523
2062
  const envTimeout = getNumberFromEnv(timeoutEnvVar);
2524
2063
  if (envTimeout != null) {
@@ -2554,11 +2093,7 @@ function getSharedConfigurationFromEnvironment(signalIdentifier) {
2554
2093
  };
2555
2094
  }
2556
2095
 
2557
- // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/convert-legacy-node-http-options.js
2558
- init_esm_shims();
2559
-
2560
2096
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/otlp-node-http-env-configuration.js
2561
- init_esm_shims();
2562
2097
  import * as fs from "fs";
2563
2098
  import * as path from "path";
2564
2099
  function getStaticHeadersFromEnv(signalIdentifier) {
@@ -2652,7 +2187,6 @@ function getNodeHttpConfigurationFromEnvironment(signalIdentifier, signalResourc
2652
2187
  }
2653
2188
 
2654
2189
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/configuration/convert-legacy-http-options.js
2655
- init_esm_shims();
2656
2190
  function convertLegacyHeaders(config) {
2657
2191
  if (typeof config.headers === "function") {
2658
2192
  return config.headers;
@@ -2699,20 +2233,7 @@ var OTLPTraceExporter = class extends OTLPExporterBase {
2699
2233
  }
2700
2234
  };
2701
2235
 
2702
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/index.js
2703
- init_esm_shims();
2704
-
2705
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/BasicTracerProvider.js
2706
- init_esm_shims();
2707
-
2708
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Tracer.js
2709
- init_esm_shims();
2710
-
2711
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Span.js
2712
- init_esm_shims();
2713
-
2714
2236
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/enums.js
2715
- init_esm_shims();
2716
2237
  var ExceptionEventName = "exception";
2717
2238
 
2718
2239
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Span.js
@@ -3064,17 +2585,7 @@ var SpanImpl = class {
3064
2585
  }
3065
2586
  };
3066
2587
 
3067
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/utility.js
3068
- init_esm_shims();
3069
-
3070
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/config.js
3071
- init_esm_shims();
3072
-
3073
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/sampler/AlwaysOffSampler.js
3074
- init_esm_shims();
3075
-
3076
2588
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Sampler.js
3077
- init_esm_shims();
3078
2589
  var SamplingDecision2;
3079
2590
  (function(SamplingDecision3) {
3080
2591
  SamplingDecision3[SamplingDecision3["NOT_RECORD"] = 0] = "NOT_RECORD";
@@ -3095,7 +2606,6 @@ var AlwaysOffSampler = class {
3095
2606
  };
3096
2607
 
3097
2608
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/sampler/AlwaysOnSampler.js
3098
- init_esm_shims();
3099
2609
  var AlwaysOnSampler = class {
3100
2610
  shouldSample() {
3101
2611
  return {
@@ -3108,7 +2618,6 @@ var AlwaysOnSampler = class {
3108
2618
  };
3109
2619
 
3110
2620
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/sampler/ParentBasedSampler.js
3111
- init_esm_shims();
3112
2621
  var ParentBasedSampler = class {
3113
2622
  _root;
3114
2623
  _remoteParentSampled;
@@ -3148,7 +2657,6 @@ var ParentBasedSampler = class {
3148
2657
  };
3149
2658
 
3150
2659
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/sampler/TraceIdRatioBasedSampler.js
3151
- init_esm_shims();
3152
2660
  var TraceIdRatioBasedSampler = class {
3153
2661
  _ratio;
3154
2662
  _upperBound;
@@ -3270,17 +2778,7 @@ function reconfigureLimits(userConfig) {
3270
2778
  return Object.assign({}, userConfig, { spanLimits });
3271
2779
  }
3272
2780
 
3273
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/index.js
3274
- init_esm_shims();
3275
-
3276
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/node/index.js
3277
- init_esm_shims();
3278
-
3279
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/node/export/BatchSpanProcessor.js
3280
- init_esm_shims();
3281
-
3282
2781
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/export/BatchSpanProcessorBase.js
3283
- init_esm_shims();
3284
2782
  var BatchSpanProcessorBase = class {
3285
2783
  _maxExportBatchSize;
3286
2784
  _maxQueueSize;
@@ -3452,7 +2950,6 @@ var BatchSpanProcessor = class extends BatchSpanProcessorBase {
3452
2950
  };
3453
2951
 
3454
2952
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/platform/node/RandomIdGenerator.js
3455
- init_esm_shims();
3456
2953
  var SPAN_ID_BYTES = 8;
3457
2954
  var TRACE_ID_BYTES = 16;
3458
2955
  var RandomIdGenerator = class {
@@ -3484,11 +2981,7 @@ function getIdGenerator(bytes) {
3484
2981
  };
3485
2982
  }
3486
2983
 
3487
- // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/TracerMetrics.js
3488
- init_esm_shims();
3489
-
3490
2984
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/semconv.js
3491
- init_esm_shims();
3492
2985
  var ATTR_OTEL_SPAN_PARENT_ORIGIN = "otel.span.parent.origin";
3493
2986
  var ATTR_OTEL_SPAN_SAMPLING_RESULT = "otel.span.sampling_result";
3494
2987
  var METRIC_OTEL_SDK_SPAN_LIVE = "otel.sdk.span.live";
@@ -3548,7 +3041,6 @@ function samplingDecisionToString(decision) {
3548
3041
  }
3549
3042
 
3550
3043
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/version.js
3551
- init_esm_shims();
3552
3044
  var VERSION3 = "2.6.1";
3553
3045
 
3554
3046
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Tracer.js
@@ -3670,7 +3162,6 @@ var Tracer = class {
3670
3162
  };
3671
3163
 
3672
3164
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/MultiSpanProcessor.js
3673
- init_esm_shims();
3674
3165
  var MultiSpanProcessor = class {
3675
3166
  _spanProcessors;
3676
3167
  constructor(spanProcessors) {
@@ -3791,8 +3282,7 @@ var BasicTracerProvider = class {
3791
3282
  };
3792
3283
 
3793
3284
  // src/lifecycle.ts
3794
- init_esm_shims();
3795
- import { EventEmitter } from "events";
3285
+ import { EventEmitter } from "node:events";
3796
3286
  var CoreState = {
3797
3287
  IDLE: "IDLE",
3798
3288
  REGISTERING: "REGISTERING",
@@ -4137,7 +3627,7 @@ function registerBeforeExitTrigger() {
4137
3627
  }
4138
3628
 
4139
3629
  // src/coexistence.ts
4140
- init_esm_shims();
3630
+ var GLASSTRACE_EXPORTER_BRAND = /* @__PURE__ */ Symbol.for("glasstrace.exporter");
4141
3631
  function createGlasstraceSpanProcessor(options) {
4142
3632
  const config = resolveConfig(options);
4143
3633
  const exporterUrl = `${config.endpoint}/v1/traces`;
@@ -4148,13 +3638,64 @@ function createGlasstraceSpanProcessor(options) {
4148
3638
  getConfig: () => getActiveConfig(),
4149
3639
  environment: config.environment,
4150
3640
  endpointUrl: exporterUrl,
4151
- createDelegate: createOtlpExporter
3641
+ createDelegate: createOtlpExporter,
3642
+ // Propagate verbose so exporter-level enrichment and export logs
3643
+ // stay observable whether the processor is built automatically by
3644
+ // the coexistence path or wired manually by the developer.
3645
+ verbose: config.verbose
4152
3646
  });
4153
3647
  registerExporterForKeyNotification(exporter);
4154
3648
  return new BatchSpanProcessor(exporter, {
4155
3649
  scheduledDelayMillis: 1e3
4156
3650
  });
4157
3651
  }
3652
+ function isGlasstraceProcessorPresent(tracerProvider) {
3653
+ try {
3654
+ const proxy = tracerProvider;
3655
+ const delegate = typeof proxy.getDelegate === "function" ? proxy.getDelegate() : tracerProvider;
3656
+ const v2 = delegate;
3657
+ const v2Processors = v2._activeSpanProcessor?._spanProcessors;
3658
+ if (Array.isArray(v2Processors) && hasBrandedProcessor(v2Processors)) {
3659
+ return true;
3660
+ }
3661
+ const v1 = delegate;
3662
+ if (typeof v1.getActiveSpanProcessor === "function") {
3663
+ const active = v1.getActiveSpanProcessor();
3664
+ const processors = active?._spanProcessors;
3665
+ if (Array.isArray(processors) && hasBrandedProcessor(processors)) {
3666
+ return true;
3667
+ }
3668
+ }
3669
+ return false;
3670
+ } catch {
3671
+ return false;
3672
+ }
3673
+ }
3674
+ function tryAutoAttachGlasstraceProcessor(tracerProvider, options) {
3675
+ try {
3676
+ if (isGlasstraceProcessorPresent(tracerProvider)) {
3677
+ return "already_present";
3678
+ }
3679
+ const proxy = tracerProvider;
3680
+ const delegate = typeof proxy.getDelegate === "function" ? proxy.getDelegate() : tracerProvider;
3681
+ const withAdd = delegate;
3682
+ if (typeof withAdd.addSpanProcessor === "function") {
3683
+ const processor2 = createGlasstraceSpanProcessor(options);
3684
+ withAdd.addSpanProcessor(processor2);
3685
+ return { method: "v1_public", processor: processor2 };
3686
+ }
3687
+ const v2 = delegate;
3688
+ const multiProcessor = v2._activeSpanProcessor;
3689
+ if (!multiProcessor || !Array.isArray(multiProcessor._spanProcessors)) {
3690
+ return null;
3691
+ }
3692
+ const processor = createGlasstraceSpanProcessor(options);
3693
+ multiProcessor._spanProcessors.push(processor);
3694
+ return { method: "v2_private", processor };
3695
+ } catch {
3696
+ return null;
3697
+ }
3698
+ }
4158
3699
  function emitNudgeMessage() {
4159
3700
  const isSentry = detectSentry();
4160
3701
  if (isSentry) {
@@ -4223,6 +3764,12 @@ Add Glasstrace to your provider configuration:
4223
3764
  );
4224
3765
  }
4225
3766
  }
3767
+ function hasBrandedProcessor(processors) {
3768
+ return processors.some((p) => {
3769
+ const exporter = p._exporter;
3770
+ return exporter?.[GLASSTRACE_EXPORTER_BRAND] === true;
3771
+ });
3772
+ }
4226
3773
  function detectSentry() {
4227
3774
  try {
4228
3775
  __require.resolve("@sentry/node");
@@ -4264,65 +3811,75 @@ async function tryImport(moduleId) {
4264
3811
  return null;
4265
3812
  }
4266
3813
  }
4267
- function tryInjectProcessor(tracerProvider, glasstraceExporter) {
4268
- try {
4269
- const proxy = tracerProvider;
4270
- const delegate = typeof proxy.getDelegate === "function" ? proxy.getDelegate() : tracerProvider;
4271
- const withAdd = delegate;
4272
- if (typeof withAdd.addSpanProcessor === "function") {
4273
- if (typeof withAdd.getActiveSpanProcessor === "function") {
4274
- const active = withAdd.getActiveSpanProcessor();
4275
- const brand = /* @__PURE__ */ Symbol.for("glasstrace.exporter");
4276
- const processors = active?._spanProcessors;
4277
- if (Array.isArray(processors) && processors.some((p) => {
4278
- const exp = p._exporter;
4279
- return exp?.[brand] === true;
4280
- })) {
4281
- return "already_present";
4282
- }
4283
- }
4284
- const processor2 = new BatchSpanProcessor(glasstraceExporter, {
4285
- scheduledDelayMillis: 1e3
4286
- });
4287
- withAdd.addSpanProcessor(processor2);
4288
- _injectedProcessor = processor2;
4289
- return "v1_public";
4290
- }
4291
- const provider = delegate;
4292
- const multiProcessor = provider._activeSpanProcessor;
4293
- if (!multiProcessor || !Array.isArray(multiProcessor._spanProcessors)) {
4294
- return null;
3814
+ async function configureOtel(config, sessionManager) {
3815
+ setOtelState(OtelState.CONFIGURING);
3816
+ await new Promise((resolve2) => {
3817
+ if (typeof setImmediate === "function") {
3818
+ setImmediate(resolve2);
3819
+ } else {
3820
+ setTimeout(resolve2, 0);
4295
3821
  }
4296
- const processor = new BatchSpanProcessor(glasstraceExporter, {
4297
- scheduledDelayMillis: 1e3
4298
- });
4299
- multiProcessor._spanProcessors.push(processor);
4300
- _injectedProcessor = processor;
4301
- return "v2_private";
4302
- } catch {
4303
- return null;
3822
+ });
3823
+ const existingProvider = trace.getTracerProvider();
3824
+ const probeTracer = existingProvider.getTracer("glasstrace-probe");
3825
+ const anotherProviderRegistered = probeTracer.constructor.name !== "ProxyTracer";
3826
+ if (anotherProviderRegistered) {
3827
+ await runCoexistencePath(existingProvider, config);
3828
+ return;
4304
3829
  }
3830
+ await runRegistrationPath(config, sessionManager);
4305
3831
  }
4306
- function isGlasstraceProcessorPresent(tracerProvider) {
4307
- try {
4308
- const proxy = tracerProvider;
4309
- const delegate = typeof proxy.getDelegate === "function" ? proxy.getDelegate() : tracerProvider;
4310
- const provider = delegate;
4311
- const processors = provider._activeSpanProcessor?._spanProcessors;
4312
- if (!Array.isArray(processors)) {
4313
- return false;
3832
+ async function runCoexistencePath(existingProvider, config) {
3833
+ const result = tryAutoAttachGlasstraceProcessor(existingProvider, {
3834
+ endpoint: config.endpoint,
3835
+ verbose: config.verbose
3836
+ });
3837
+ if (result === "already_present") {
3838
+ if (config.verbose) {
3839
+ sdkLog("info", "[glasstrace] Existing provider detected \u2014 Glasstrace processor already present.");
3840
+ }
3841
+ setOtelState(OtelState.PROCESSOR_PRESENT);
3842
+ emitLifecycleEvent("otel:configured", { state: OtelState.PROCESSOR_PRESENT, scenario: "B-clean" });
3843
+ return;
3844
+ }
3845
+ if (result !== null) {
3846
+ _injectedProcessor = result.processor;
3847
+ if (config.verbose) {
3848
+ sdkLog(
3849
+ "info",
3850
+ "[glasstrace] Existing provider detected \u2014 auto-attached Glasstrace span processor."
3851
+ );
4314
3852
  }
4315
- const brand = /* @__PURE__ */ Symbol.for("glasstrace.exporter");
4316
- return processors.some((p) => {
4317
- const exporter = p._exporter;
4318
- return exporter?.[brand] === true;
3853
+ registerShutdownHook({
3854
+ name: "coexistence-flush",
3855
+ priority: 5,
3856
+ fn: async () => {
3857
+ if (_injectedProcessor) {
3858
+ await _injectedProcessor.forceFlush();
3859
+ }
3860
+ }
4319
3861
  });
4320
- } catch {
4321
- return false;
3862
+ registerBeforeExitTrigger();
3863
+ const scenario = result.method === "v1_public" ? "D1" : "B-auto";
3864
+ setOtelState(OtelState.AUTO_ATTACHED);
3865
+ emitLifecycleEvent("otel:configured", { state: OtelState.AUTO_ATTACHED, scenario });
3866
+ emitLifecycleEvent("otel:injection_succeeded", { method: result.method });
3867
+ emitNudgeMessage();
3868
+ return;
3869
+ }
3870
+ if (config.verbose) {
3871
+ sdkLog("info", "[glasstrace] Existing provider detected \u2014 could not auto-attach.");
3872
+ }
3873
+ emitGuidanceMessage();
3874
+ setOtelState(OtelState.COEXISTENCE_FAILED);
3875
+ emitLifecycleEvent("otel:configured", { state: OtelState.COEXISTENCE_FAILED, scenario: "C/F" });
3876
+ emitLifecycleEvent("otel:injection_failed", { reason: "provider internals inaccessible" });
3877
+ const coreState = getCoreState();
3878
+ if (coreState === CoreState.ACTIVE || coreState === CoreState.KEY_RESOLVED) {
3879
+ setCoreState(CoreState.ACTIVE_DEGRADED);
4322
3880
  }
4323
3881
  }
4324
- async function configureOtel(config, sessionManager) {
4325
- setOtelState(OtelState.CONFIGURING);
3882
+ async function runRegistrationPath(config, sessionManager) {
4326
3883
  const exporterUrl = `${config.endpoint}/v1/traces`;
4327
3884
  const createOtlpExporter = (url, headers) => new OTLPTraceExporter({ url, headers });
4328
3885
  const glasstraceExporter = new GlasstraceExporter({
@@ -4335,71 +3892,6 @@ async function configureOtel(config, sessionManager) {
4335
3892
  verbose: config.verbose
4336
3893
  });
4337
3894
  _activeExporter = glasstraceExporter;
4338
- await new Promise((resolve2) => {
4339
- if (typeof setImmediate === "function") {
4340
- setImmediate(resolve2);
4341
- } else {
4342
- setTimeout(resolve2, 0);
4343
- }
4344
- });
4345
- const existingProvider = trace.getTracerProvider();
4346
- const probeTracer = existingProvider.getTracer("glasstrace-probe");
4347
- const anotherProviderRegistered = probeTracer.constructor.name !== "ProxyTracer";
4348
- if (anotherProviderRegistered) {
4349
- if (isGlasstraceProcessorPresent(existingProvider)) {
4350
- if (config.verbose) {
4351
- sdkLog("info", "[glasstrace] Existing provider detected \u2014 Glasstrace processor already present.");
4352
- }
4353
- _activeExporter = null;
4354
- setOtelState(OtelState.PROCESSOR_PRESENT);
4355
- emitLifecycleEvent("otel:configured", { state: OtelState.PROCESSOR_PRESENT, scenario: "B-clean" });
4356
- return;
4357
- }
4358
- const injectionMethod = tryInjectProcessor(existingProvider, glasstraceExporter);
4359
- if (injectionMethod === "already_present") {
4360
- if (config.verbose) {
4361
- sdkLog("info", "[glasstrace] Existing provider detected \u2014 Glasstrace processor already present (v1 check).");
4362
- }
4363
- _activeExporter = null;
4364
- setOtelState(OtelState.PROCESSOR_PRESENT);
4365
- emitLifecycleEvent("otel:configured", { state: OtelState.PROCESSOR_PRESENT, scenario: "B-clean" });
4366
- return;
4367
- }
4368
- if (injectionMethod) {
4369
- if (config.verbose) {
4370
- sdkLog("info", "[glasstrace] Existing provider detected \u2014 auto-attaching Glasstrace processor.");
4371
- }
4372
- registerShutdownHook({
4373
- name: "coexistence-flush",
4374
- priority: 5,
4375
- fn: async () => {
4376
- if (_injectedProcessor) {
4377
- await _injectedProcessor.forceFlush();
4378
- }
4379
- }
4380
- });
4381
- registerBeforeExitTrigger();
4382
- const scenario = injectionMethod === "v1_public" ? "D1" : "B-auto";
4383
- setOtelState(OtelState.AUTO_ATTACHED);
4384
- emitLifecycleEvent("otel:configured", { state: OtelState.AUTO_ATTACHED, scenario });
4385
- emitLifecycleEvent("otel:injection_succeeded", { method: injectionMethod });
4386
- emitNudgeMessage();
4387
- return;
4388
- }
4389
- if (config.verbose) {
4390
- sdkLog("info", "[glasstrace] Existing provider detected \u2014 could not auto-attach.");
4391
- }
4392
- emitGuidanceMessage();
4393
- _activeExporter = null;
4394
- setOtelState(OtelState.COEXISTENCE_FAILED);
4395
- emitLifecycleEvent("otel:configured", { state: OtelState.COEXISTENCE_FAILED, scenario: "C/F" });
4396
- emitLifecycleEvent("otel:injection_failed", { reason: "provider internals inaccessible" });
4397
- const coreState = getCoreState();
4398
- if (coreState === CoreState.ACTIVE || coreState === CoreState.KEY_RESOLVED) {
4399
- setCoreState(CoreState.ACTIVE_DEGRADED);
4400
- }
4401
- return;
4402
- }
4403
3895
  const vercelOtel = await tryImport("@vercel/otel");
4404
3896
  if (vercelOtel && typeof vercelOtel.registerOTel === "function") {
4405
3897
  const otelConfig = {
@@ -4462,8 +3954,7 @@ async function configureOtel(config, sessionManager) {
4462
3954
  }
4463
3955
 
4464
3956
  // src/context-manager.ts
4465
- init_esm_shims();
4466
- import { AsyncLocalStorage } from "async_hooks";
3957
+ import { AsyncLocalStorage } from "node:async_hooks";
4467
3958
  function installContextManager() {
4468
3959
  try {
4469
3960
  const als = new AsyncLocalStorage();
@@ -4493,7 +3984,6 @@ function installContextManager() {
4493
3984
  }
4494
3985
 
4495
3986
  // src/heartbeat.ts
4496
- init_esm_shims();
4497
3987
  var HEARTBEAT_INTERVAL_MS = 5 * 60 * 1e3;
4498
3988
  var BACKOFF_BASE_MS = HEARTBEAT_INTERVAL_MS;
4499
3989
  var BACKOFF_MAX_MS = 30 * 60 * 1e3;
@@ -4529,8 +4019,8 @@ function checkShutdownMarker(projectRoot) {
4529
4019
  let fsSync = null;
4530
4020
  let pathSync = null;
4531
4021
  try {
4532
- fsSync = __require("fs");
4533
- pathSync = __require("path");
4022
+ fsSync = __require("node:fs");
4023
+ pathSync = __require("node:path");
4534
4024
  } catch {
4535
4025
  return { triggered: false };
4536
4026
  }
@@ -4618,9 +4108,8 @@ function registerHeartbeatShutdownHook(config, anonKey, sdkVersion) {
4618
4108
  }
4619
4109
 
4620
4110
  // src/runtime-state.ts
4621
- init_esm_shims();
4622
- import { writeFileSync, renameSync, mkdirSync } from "fs";
4623
- import { join } from "path";
4111
+ import { writeFileSync, renameSync, mkdirSync } from "node:fs";
4112
+ import { join } from "node:path";
4624
4113
  var _projectRoot = null;
4625
4114
  var _sdkVersion = "unknown";
4626
4115
  var _lastScenario;
@@ -4715,7 +4204,7 @@ function registerGlasstrace(options) {
4715
4204
  setCoreState(CoreState.REGISTERING);
4716
4205
  startRuntimeStateWriter({
4717
4206
  projectRoot: process.cwd(),
4718
- sdkVersion: "0.15.1"
4207
+ sdkVersion: "0.17.0"
4719
4208
  });
4720
4209
  const config = resolveConfig(options);
4721
4210
  if (config.verbose) {
@@ -4880,8 +4369,8 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4880
4369
  if (config.verbose) {
4881
4370
  console.info("[glasstrace] Background init firing.");
4882
4371
  }
4883
- const healthReport = collectHealthReport("0.15.1");
4884
- const initResult = await performInit(config, anonKeyForInit, "0.15.1", healthReport);
4372
+ const healthReport = collectHealthReport("0.17.0");
4373
+ const initResult = await performInit(config, anonKeyForInit, "0.17.0", healthReport);
4885
4374
  if (generation !== registrationGeneration) return;
4886
4375
  const currentState = getCoreState();
4887
4376
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -4904,7 +4393,7 @@ async function backgroundInit(config, anonKeyForInit, generation) {
4904
4393
  }
4905
4394
  maybeInstallConsoleCapture();
4906
4395
  if (didLastInitSucceed()) {
4907
- startHeartbeat(config, anonKeyForInit, "0.15.1", generation, (newApiKey, accountId) => {
4396
+ startHeartbeat(config, anonKeyForInit, "0.17.0", generation, (newApiKey, accountId) => {
4908
4397
  setAuthState(AuthState.CLAIMING);
4909
4398
  emitLifecycleEvent("auth:claim_started", { accountId });
4910
4399
  setResolvedApiKey(newApiKey);
@@ -4934,7 +4423,7 @@ function isDiscoveryEnabled(config) {
4934
4423
  }
4935
4424
 
4936
4425
  // src/config-wrapper.ts
4937
- init_esm_shims();
4426
+ import { isBuiltin as isNodeBuiltin } from "node:module";
4938
4427
  function isTurbopackBuild() {
4939
4428
  if (typeof process === "undefined") return false;
4940
4429
  const argv = Array.isArray(process.argv) ? process.argv : [];
@@ -4943,6 +4432,36 @@ function isTurbopackBuild() {
4943
4432
  if (process.env?.TURBOPACK === "1") return true;
4944
4433
  return false;
4945
4434
  }
4435
+ var SDK_PACKAGE_NAME = "@glasstrace/sdk";
4436
+ function appendNodeSchemeExternal(webpackConfig) {
4437
+ const nodeBuiltinExternal = (data, callback) => {
4438
+ const request = data.request;
4439
+ if (typeof request === "string" && isNodeBuiltin(request)) {
4440
+ callback(null, "commonjs " + request);
4441
+ return;
4442
+ }
4443
+ callback(null);
4444
+ };
4445
+ const existing = webpackConfig.externals;
4446
+ if (Array.isArray(existing)) {
4447
+ webpackConfig.externals = [...existing, nodeBuiltinExternal];
4448
+ } else if (existing == null) {
4449
+ webpackConfig.externals = [nodeBuiltinExternal];
4450
+ } else {
4451
+ webpackConfig.externals = [existing, nodeBuiltinExternal];
4452
+ }
4453
+ }
4454
+ function ensureServerExternal(config) {
4455
+ const existingStable = config.serverExternalPackages;
4456
+ const stable = Array.isArray(existingStable) ? (
4457
+ // Clone so we never mutate a caller-owned array in place.
4458
+ existingStable.filter((entry) => typeof entry === "string")
4459
+ ) : [];
4460
+ if (!stable.includes(SDK_PACKAGE_NAME)) {
4461
+ stable.push(SDK_PACKAGE_NAME);
4462
+ }
4463
+ config.serverExternalPackages = stable;
4464
+ }
4946
4465
  function withGlasstraceConfig(nextConfig) {
4947
4466
  if (typeof process === "undefined" || typeof process.versions?.node !== "string") {
4948
4467
  return nextConfig != null ? { ...nextConfig } : {};
@@ -4954,6 +4473,7 @@ function withGlasstraceConfig(nextConfig) {
4954
4473
  ...existingExperimental,
4955
4474
  serverSourceMaps: true
4956
4475
  };
4476
+ ensureServerExternal(bag);
4957
4477
  if (bag.turbopack == null) {
4958
4478
  bag.turbopack = {};
4959
4479
  }
@@ -4968,6 +4488,9 @@ function withGlasstraceConfig(nextConfig) {
4968
4488
  result = existingWebpack(webpackConfig, context2);
4969
4489
  }
4970
4490
  const webpackContext = context2;
4491
+ if (webpackContext.isServer) {
4492
+ appendNodeSchemeExternal(result);
4493
+ }
4971
4494
  if (!webpackContext.isServer && webpackContext.dev === false) {
4972
4495
  const plugins = result.plugins ?? [];
4973
4496
  plugins.push({
@@ -5007,7 +4530,7 @@ async function handleSourceMapUpload(distDir) {
5007
4530
  );
5008
4531
  return;
5009
4532
  }
5010
- const { discoverSourceMapFiles: discoverSourceMapFiles2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-3GWUQDTS.js");
4533
+ const { discoverSourceMapFiles: discoverSourceMapFiles2, computeBuildHash: computeBuildHash2, uploadSourceMaps: uploadSourceMaps2 } = await import("./source-map-uploader-26QPRSCG.js");
5011
4534
  const files = await discoverSourceMapFiles2(distDir);
5012
4535
  if (files.length === 0) {
5013
4536
  console.info("[glasstrace] No source map files found. Skipping upload.");
@@ -5027,7 +4550,6 @@ async function handleSourceMapUpload(distDir) {
5027
4550
  }
5028
4551
 
5029
4552
  // src/capture-error.ts
5030
- init_esm_shims();
5031
4553
  function captureError(error) {
5032
4554
  try {
5033
4555
  const span = trace.getSpan(context.active());
@@ -5046,6 +4568,67 @@ function captureError(error) {
5046
4568
  } catch {
5047
4569
  }
5048
4570
  }
4571
+
4572
+ // src/correlation-id.ts
4573
+ var ATTR2 = GLASSTRACE_ATTRIBUTE_NAMES;
4574
+ var HEADER_NAME = "x-gt-cid";
4575
+ var MAX_CID_LENGTH = 128;
4576
+ function captureCorrelationId(req) {
4577
+ try {
4578
+ if (!req || !req.headers) {
4579
+ return;
4580
+ }
4581
+ const value = readHeader(req.headers);
4582
+ if (!value) {
4583
+ return;
4584
+ }
4585
+ const span = trace.getActiveSpan();
4586
+ if (!span) {
4587
+ return;
4588
+ }
4589
+ span.setAttribute(ATTR2.CORRELATION_ID, value);
4590
+ } catch {
4591
+ }
4592
+ }
4593
+ function readHeader(headers) {
4594
+ const asFetch = headers;
4595
+ if (typeof asFetch.get === "function") {
4596
+ const raw = asFetch.get(HEADER_NAME);
4597
+ return firstToken(raw);
4598
+ }
4599
+ const dict = headers;
4600
+ const direct = dict[HEADER_NAME];
4601
+ if (direct !== void 0) {
4602
+ return firstValue(direct);
4603
+ }
4604
+ for (const key of Object.keys(dict)) {
4605
+ if (key.toLowerCase() === HEADER_NAME) {
4606
+ return firstValue(dict[key]);
4607
+ }
4608
+ }
4609
+ return void 0;
4610
+ }
4611
+ function firstValue(value) {
4612
+ if (Array.isArray(value)) {
4613
+ for (const entry of value) {
4614
+ const token = firstToken(entry);
4615
+ if (token) return token;
4616
+ }
4617
+ return void 0;
4618
+ }
4619
+ return firstToken(value);
4620
+ }
4621
+ function firstToken(value) {
4622
+ if (typeof value !== "string") return void 0;
4623
+ const parts = value.split(",");
4624
+ for (const part of parts) {
4625
+ const trimmed = part.trim();
4626
+ if (trimmed.length === 0) continue;
4627
+ if (trimmed.length > MAX_CID_LENGTH) return void 0;
4628
+ return trimmed;
4629
+ }
4630
+ return void 0;
4631
+ }
5049
4632
  export {
5050
4633
  GlasstraceExporter,
5051
4634
  GlasstraceSpanProcessor,
@@ -5053,6 +4636,7 @@ export {
5053
4636
  SdkError,
5054
4637
  SessionManager,
5055
4638
  buildImportGraph,
4639
+ captureCorrelationId,
5056
4640
  captureError,
5057
4641
  classifyFetchTarget,
5058
4642
  collectSourceMaps,