@glasstrace/sdk 1.0.1 → 1.1.1

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 (60) hide show
  1. package/README.md +3 -2
  2. package/dist/{chunk-KE7MCPO5.js → chunk-4EZ6JTDG.js} +2 -2
  3. package/dist/{chunk-67RIOAXV.js → chunk-6RNBUUBR.js} +2 -2
  4. package/dist/{chunk-DXRZKKSO.js → chunk-7SZQN6IU.js} +1 -3
  5. package/dist/chunk-7SZQN6IU.js.map +1 -0
  6. package/dist/{chunk-55FBXXER.js → chunk-DIM4JRXM.js} +2 -2
  7. package/dist/{chunk-UGJ3X4CT.js → chunk-DST4UBXU.js} +2 -2
  8. package/dist/{chunk-DO2YPMQ5.js → chunk-MXDZHFJQ.js} +23 -5
  9. package/dist/chunk-MXDZHFJQ.js.map +1 -0
  10. package/dist/chunk-P22UQ2OJ.js +384 -0
  11. package/dist/chunk-P22UQ2OJ.js.map +1 -0
  12. package/dist/{chunk-HAU66QBQ.js → chunk-P4OYPFQ5.js} +9 -9
  13. package/dist/chunk-P4OYPFQ5.js.map +1 -0
  14. package/dist/{chunk-TQ54WLCZ.js → chunk-X5MAXP5T.js} +2 -1
  15. package/dist/{chunk-MV3F7HVX.js → chunk-Y26HJUPD.js} +49 -27
  16. package/dist/{chunk-MV3F7HVX.js.map → chunk-Y26HJUPD.js.map} +1 -1
  17. package/dist/{chunk-LU3PPAOQ.js → chunk-ZRDQ6ZKI.js} +474 -93
  18. package/dist/chunk-ZRDQ6ZKI.js.map +1 -0
  19. package/dist/cli/init.cjs +1118 -946
  20. package/dist/cli/init.cjs.map +1 -1
  21. package/dist/cli/init.js +42 -29
  22. package/dist/cli/init.js.map +1 -1
  23. package/dist/cli/mcp-add.cjs +243 -83
  24. package/dist/cli/mcp-add.cjs.map +1 -1
  25. package/dist/cli/mcp-add.d.cts +35 -4
  26. package/dist/cli/mcp-add.d.ts +35 -4
  27. package/dist/cli/mcp-add.js +48 -24
  28. package/dist/cli/mcp-add.js.map +1 -1
  29. package/dist/cli/status.cjs.map +1 -1
  30. package/dist/cli/status.js +3 -1
  31. package/dist/cli/status.js.map +1 -1
  32. package/dist/cli/uninit.cjs +4 -4
  33. package/dist/cli/uninit.cjs.map +1 -1
  34. package/dist/cli/uninit.js +4 -4
  35. package/dist/edge-entry.js +2 -2
  36. package/dist/index.cjs +423 -118
  37. package/dist/index.cjs.map +1 -1
  38. package/dist/index.js +5 -5
  39. package/dist/{monorepo-N5Z63XP7.js → monorepo-GSL6JD3G.js} +5 -3
  40. package/dist/node-entry.cjs +423 -118
  41. package/dist/node-entry.cjs.map +1 -1
  42. package/dist/node-entry.js +7 -7
  43. package/dist/node-subpath.js +3 -3
  44. package/dist/{source-map-uploader-BJIXRLJ6.js → source-map-uploader-DPUUCLNW.js} +3 -3
  45. package/package.json +6 -6
  46. package/dist/chunk-DO2YPMQ5.js.map +0 -1
  47. package/dist/chunk-DXRZKKSO.js.map +0 -1
  48. package/dist/chunk-HAU66QBQ.js.map +0 -1
  49. package/dist/chunk-IP4NMDJK.js +0 -98
  50. package/dist/chunk-IP4NMDJK.js.map +0 -1
  51. package/dist/chunk-LU3PPAOQ.js.map +0 -1
  52. package/dist/chunk-O63DJKIJ.js +0 -460
  53. package/dist/chunk-O63DJKIJ.js.map +0 -1
  54. /package/dist/{chunk-KE7MCPO5.js.map → chunk-4EZ6JTDG.js.map} +0 -0
  55. /package/dist/{chunk-67RIOAXV.js.map → chunk-6RNBUUBR.js.map} +0 -0
  56. /package/dist/{chunk-55FBXXER.js.map → chunk-DIM4JRXM.js.map} +0 -0
  57. /package/dist/{chunk-UGJ3X4CT.js.map → chunk-DST4UBXU.js.map} +0 -0
  58. /package/dist/{chunk-TQ54WLCZ.js.map → chunk-X5MAXP5T.js.map} +0 -0
  59. /package/dist/{monorepo-N5Z63XP7.js.map → monorepo-GSL6JD3G.js.map} +0 -0
  60. /package/dist/{source-map-uploader-BJIXRLJ6.js.map → source-map-uploader-DPUUCLNW.js.map} +0 -0
@@ -17103,6 +17103,7 @@ function firstToken(value) {
17103
17103
  init_dist();
17104
17104
  var GLASSTRACE_DIR = ".glasstrace";
17105
17105
  var ANON_KEY_FILE = "anon_key";
17106
+ var CLAIMED_KEY_FILE = "claimed-key";
17106
17107
  var fsPathCache;
17107
17108
  async function loadFsPath() {
17108
17109
  if (fsPathCache !== void 0) return fsPathCache;
@@ -17139,6 +17140,22 @@ async function readAnonKey(projectRoot) {
17139
17140
  }
17140
17141
  return null;
17141
17142
  }
17143
+ async function readClaimedKey(projectRoot) {
17144
+ const root = projectRoot ?? process.cwd();
17145
+ const modules = await loadFsPath();
17146
+ if (!modules) return null;
17147
+ const keyPath = modules.path.join(root, GLASSTRACE_DIR, CLAIMED_KEY_FILE);
17148
+ try {
17149
+ const content = await modules.fs.readFile(keyPath, "utf-8");
17150
+ const trimmed = content.trim();
17151
+ const parsed = DevApiKeySchema.safeParse(trimmed);
17152
+ if (parsed.success) {
17153
+ return parsed.data;
17154
+ }
17155
+ } catch {
17156
+ }
17157
+ return null;
17158
+ }
17142
17159
  async function getOrCreateAnonKey(projectRoot) {
17143
17160
  const root = projectRoot ?? process.cwd();
17144
17161
  const existingKey = await readAnonKey(root);
@@ -17475,8 +17492,259 @@ function sleep(ms, scheduler, signal) {
17475
17492
  });
17476
17493
  }
17477
17494
 
17478
- // src/init-client.ts
17495
+ // src/mcp-runtime.ts
17496
+ var import_node_crypto = require("node:crypto");
17497
+ init_dist();
17498
+ var MCP_ENDPOINT = "https://api.glasstrace.dev/mcp";
17499
+ var fsPathCache2;
17500
+ async function loadFsPath2() {
17501
+ if (fsPathCache2 !== void 0) return fsPathCache2;
17502
+ try {
17503
+ const [fs4, path4] = await Promise.all([
17504
+ import("node:fs/promises"),
17505
+ import("node:path")
17506
+ ]);
17507
+ fsPathCache2 = { fs: fs4, path: path4 };
17508
+ return fsPathCache2;
17509
+ } catch {
17510
+ fsPathCache2 = null;
17511
+ return null;
17512
+ }
17513
+ }
17514
+ function identityFingerprint(token) {
17515
+ return `sha256:${(0, import_node_crypto.createHash)("sha256").update(token).digest("hex")}`;
17516
+ }
17517
+ function mcpConfigMatches(existingContent, expectedContent) {
17518
+ const trimmedExpected = expectedContent.trim();
17519
+ try {
17520
+ const existingParsed = JSON.parse(existingContent);
17521
+ const expectedParsed = JSON.parse(trimmedExpected);
17522
+ return JSON.stringify(canonicalize(existingParsed)) === JSON.stringify(canonicalize(expectedParsed));
17523
+ } catch {
17524
+ }
17525
+ return existingContent.trim() === trimmedExpected;
17526
+ }
17527
+ function canonicalize(value) {
17528
+ if (Array.isArray(value)) {
17529
+ return value.map(canonicalize);
17530
+ }
17531
+ if (value !== null && typeof value === "object") {
17532
+ const obj = value;
17533
+ const sorted = {};
17534
+ for (const key of Object.keys(obj).sort()) {
17535
+ sorted[key] = canonicalize(obj[key]);
17536
+ }
17537
+ return sorted;
17538
+ }
17539
+ return value;
17540
+ }
17541
+ function readEnvLocalApiKey(content) {
17542
+ let last = null;
17543
+ const regex = /^\s*GLASSTRACE_API_KEY\s*=\s*(.*)$/gm;
17544
+ let match;
17545
+ while ((match = regex.exec(content)) !== null) {
17546
+ const raw = match[1].trim();
17547
+ if (raw === "") continue;
17548
+ const unquoted = raw.replace(/^(['"])(.*)\1$/, "$2");
17549
+ if (unquoted === "" || unquoted === "your_key_here") continue;
17550
+ last = unquoted;
17551
+ }
17552
+ return last;
17553
+ }
17554
+ async function resolveEffectiveMcpCredential(projectRoot) {
17555
+ const root = projectRoot ?? process.cwd();
17556
+ const warnings = [];
17557
+ const envLocalKey = await readEnvLocalDevKey(root, warnings);
17558
+ const claimedKey = envLocalKey === null ? await readClaimedKey(root) : null;
17559
+ const anonKey = await readAnonKey(root);
17560
+ let effective = null;
17561
+ if (envLocalKey !== null) {
17562
+ effective = { source: "env-local", key: envLocalKey };
17563
+ } else if (claimedKey !== null) {
17564
+ effective = { source: "claimed-key", key: claimedKey };
17565
+ warnings.push("claimed-key-only");
17566
+ } else if (anonKey !== null) {
17567
+ effective = { source: "anon", key: anonKey };
17568
+ }
17569
+ return { effective, anonKey, warnings };
17570
+ }
17571
+ async function readEnvLocalDevKey(root, warnings) {
17572
+ const modules = await loadFsPath2();
17573
+ if (!modules) return null;
17574
+ const envPath = modules.path.join(root, ".env.local");
17575
+ let content;
17576
+ try {
17577
+ content = await modules.fs.readFile(envPath, "utf-8");
17578
+ } catch {
17579
+ return null;
17580
+ }
17581
+ const raw = readEnvLocalApiKey(content);
17582
+ if (raw === null) return null;
17583
+ const parsed = DevApiKeySchema.safeParse(raw);
17584
+ if (!parsed.success) {
17585
+ warnings.push("malformed-env-local");
17586
+ return null;
17587
+ }
17588
+ return parsed.data;
17589
+ }
17590
+ var MCP_MARKER_FILE = "mcp-connected";
17479
17591
  var GLASSTRACE_DIR2 = ".glasstrace";
17592
+ async function readMcpMarker(projectRoot) {
17593
+ const root = projectRoot ?? process.cwd();
17594
+ const modules = await loadFsPath2();
17595
+ if (!modules) return { status: "absent" };
17596
+ const markerPath = modules.path.join(root, GLASSTRACE_DIR2, MCP_MARKER_FILE);
17597
+ let content;
17598
+ try {
17599
+ content = await modules.fs.readFile(markerPath, "utf-8");
17600
+ } catch {
17601
+ return { status: "absent" };
17602
+ }
17603
+ let parsed;
17604
+ try {
17605
+ parsed = JSON.parse(content);
17606
+ } catch {
17607
+ return { status: "corrupted" };
17608
+ }
17609
+ if (parsed === null || typeof parsed !== "object") {
17610
+ return { status: "corrupted" };
17611
+ }
17612
+ const obj = parsed;
17613
+ const version2 = obj["version"];
17614
+ if (version2 === void 0) {
17615
+ const keyHash = obj["keyHash"];
17616
+ if (typeof keyHash !== "string" || keyHash === "") {
17617
+ return { status: "corrupted" };
17618
+ }
17619
+ return {
17620
+ status: "valid",
17621
+ credentialSource: "anon",
17622
+ credentialHash: keyHash
17623
+ };
17624
+ }
17625
+ if (version2 === 2) {
17626
+ const source = obj["credentialSource"];
17627
+ const hash2 = obj["credentialHash"];
17628
+ if (source !== "env-local" && source !== "claimed-key" && source !== "anon" || typeof hash2 !== "string" || hash2 === "") {
17629
+ return { status: "corrupted" };
17630
+ }
17631
+ return {
17632
+ status: "valid",
17633
+ credentialSource: source,
17634
+ credentialHash: hash2
17635
+ };
17636
+ }
17637
+ if (typeof version2 === "number" && version2 > 2) {
17638
+ return { status: "unknown-version" };
17639
+ }
17640
+ return { status: "corrupted" };
17641
+ }
17642
+ async function writeMcpMarker(projectRoot, target) {
17643
+ const modules = await loadFsPath2();
17644
+ if (!modules) return false;
17645
+ const dirPath = modules.path.join(projectRoot, GLASSTRACE_DIR2);
17646
+ const markerPath = modules.path.join(dirPath, MCP_MARKER_FILE);
17647
+ const state = await readMcpMarker(projectRoot);
17648
+ if (state.status === "valid" && state.credentialSource === target.credentialSource && state.credentialHash === target.credentialHash) {
17649
+ return false;
17650
+ }
17651
+ await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
17652
+ const body = JSON.stringify(
17653
+ {
17654
+ version: 2,
17655
+ credentialSource: target.credentialSource,
17656
+ credentialHash: target.credentialHash,
17657
+ configuredAt: (/* @__PURE__ */ new Date()).toISOString()
17658
+ },
17659
+ null,
17660
+ 2
17661
+ );
17662
+ await modules.fs.writeFile(markerPath, body, { mode: 384 });
17663
+ await modules.fs.chmod(markerPath, 384);
17664
+ return true;
17665
+ }
17666
+ var MCP_CONFIG_FILE = "mcp.json";
17667
+ var refreshNudgeEmitted = false;
17668
+ function emitRefreshNudge(persistedSource) {
17669
+ if (refreshNudgeEmitted) return;
17670
+ refreshNudgeEmitted = true;
17671
+ try {
17672
+ if (persistedSource === "claimed-key") {
17673
+ process.stderr.write(
17674
+ "[glasstrace] MCP config refreshed for the new credential. Copy .glasstrace/claimed-key into .env.local so Codex can pick it up on next restart.\n"
17675
+ );
17676
+ } else {
17677
+ process.stderr.write(
17678
+ "[glasstrace] MCP config refreshed for the new credential.\n"
17679
+ );
17680
+ }
17681
+ } catch {
17682
+ }
17683
+ }
17684
+ function genericMcpConfigContent(endpoint, bearer) {
17685
+ return JSON.stringify(
17686
+ {
17687
+ mcpServers: {
17688
+ glasstrace: {
17689
+ url: endpoint,
17690
+ headers: {
17691
+ Authorization: `Bearer ${bearer}`
17692
+ }
17693
+ }
17694
+ }
17695
+ },
17696
+ null,
17697
+ 2
17698
+ );
17699
+ }
17700
+ async function refreshGenericMcpConfigAtRuntime(projectRoot, effective, anonKeyOnDisk) {
17701
+ if (effective === null || effective.source === "anon") {
17702
+ return { action: "skipped-anon-source" };
17703
+ }
17704
+ if (anonKeyOnDisk === null) {
17705
+ return { action: "absent" };
17706
+ }
17707
+ const modules = await loadFsPath2();
17708
+ if (!modules) return { action: "absent" };
17709
+ const dirPath = modules.path.join(projectRoot, GLASSTRACE_DIR2);
17710
+ const configPath = modules.path.join(dirPath, MCP_CONFIG_FILE);
17711
+ const tmpPath = configPath + ".tmp";
17712
+ let existing;
17713
+ try {
17714
+ existing = await modules.fs.readFile(configPath, "utf-8");
17715
+ } catch (err) {
17716
+ const code = err.code;
17717
+ if (code === "ENOENT") {
17718
+ return { action: "absent" };
17719
+ }
17720
+ return { action: "preserved" };
17721
+ }
17722
+ const expectedAnon = genericMcpConfigContent(MCP_ENDPOINT, anonKeyOnDisk);
17723
+ if (!mcpConfigMatches(existing, expectedAnon)) {
17724
+ return { action: "preserved" };
17725
+ }
17726
+ const replacement = genericMcpConfigContent(MCP_ENDPOINT, effective.key);
17727
+ try {
17728
+ await modules.fs.writeFile(tmpPath, replacement, { mode: 384 });
17729
+ await modules.fs.chmod(tmpPath, 384);
17730
+ await modules.fs.rename(tmpPath, configPath);
17731
+ await writeMcpMarker(projectRoot, {
17732
+ credentialSource: effective.source,
17733
+ credentialHash: identityFingerprint(effective.key)
17734
+ });
17735
+ } catch {
17736
+ try {
17737
+ await modules.fs.unlink(tmpPath);
17738
+ } catch {
17739
+ }
17740
+ return { action: "preserved" };
17741
+ }
17742
+ emitRefreshNudge(effective.source);
17743
+ return { action: "rewrote" };
17744
+ }
17745
+
17746
+ // src/init-client.ts
17747
+ var GLASSTRACE_DIR3 = ".glasstrace";
17480
17748
  var CONFIG_FILE = "config";
17481
17749
  var TWENTY_FOUR_HOURS_MS = 24 * 60 * 60 * 1e3;
17482
17750
  var INIT_TIMEOUT_MS = 1e4;
@@ -17513,7 +17781,7 @@ function loadCachedConfig(projectRoot) {
17513
17781
  const modules = loadFsSyncOrNull();
17514
17782
  if (!modules) return null;
17515
17783
  const root = projectRoot ?? process.cwd();
17516
- const configPath = modules.join(root, GLASSTRACE_DIR2, CONFIG_FILE);
17784
+ const configPath = modules.join(root, GLASSTRACE_DIR3, CONFIG_FILE);
17517
17785
  try {
17518
17786
  const content = modules.readFileSync(configPath, "utf-8");
17519
17787
  const parsed = JSON.parse(content);
@@ -17539,7 +17807,7 @@ async function saveCachedConfig(response, projectRoot) {
17539
17807
  const modules = await loadFsPathAsync();
17540
17808
  if (!modules) return;
17541
17809
  const root = projectRoot ?? process.cwd();
17542
- const dirPath = modules.path.join(root, GLASSTRACE_DIR2);
17810
+ const dirPath = modules.path.join(root, GLASSTRACE_DIR3);
17543
17811
  const configPath = modules.path.join(dirPath, CONFIG_FILE);
17544
17812
  const tmpPath = `${configPath}.tmp`;
17545
17813
  try {
@@ -17665,11 +17933,11 @@ async function writeClaimedKey(newApiKey, projectRoot) {
17665
17933
  );
17666
17934
  } catch {
17667
17935
  }
17668
- return;
17936
+ return { persisted: "env-local" };
17669
17937
  }
17670
17938
  let claimedKeyWritten = false;
17671
17939
  try {
17672
- const dirPath = modules.path.join(root, GLASSTRACE_DIR2);
17940
+ const dirPath = modules.path.join(root, GLASSTRACE_DIR3);
17673
17941
  await modules.fs.mkdir(dirPath, { recursive: true, mode: 448 });
17674
17942
  await modules.fs.chmod(dirPath, 448);
17675
17943
  const claimedKeyPath = modules.path.join(dirPath, "claimed-key");
@@ -17688,7 +17956,7 @@ async function writeClaimedKey(newApiKey, projectRoot) {
17688
17956
  );
17689
17957
  } catch {
17690
17958
  }
17691
- return;
17959
+ return { persisted: "claimed-key" };
17692
17960
  }
17693
17961
  }
17694
17962
  try {
@@ -17697,6 +17965,7 @@ async function writeClaimedKey(newApiKey, projectRoot) {
17697
17965
  );
17698
17966
  } catch {
17699
17967
  }
17968
+ return { persisted: "none" };
17700
17969
  }
17701
17970
  async function performInit(config2, anonKey, sdkVersion, healthReport) {
17702
17971
  lastInitSucceeded = false;
@@ -17728,10 +17997,23 @@ async function performInit(config2, anonKey, sdkVersion, healthReport) {
17728
17997
  lastInitSucceeded = true;
17729
17998
  await saveCachedConfig(result);
17730
17999
  if (result.claimResult) {
18000
+ let persisted = "none";
17731
18001
  try {
17732
- await writeClaimedKey(result.claimResult.newApiKey);
18002
+ const w = await writeClaimedKey(result.claimResult.newApiKey);
18003
+ persisted = w.persisted;
17733
18004
  } catch {
17734
18005
  }
18006
+ if (persisted !== "none") {
18007
+ try {
18008
+ const resolved = await resolveEffectiveMcpCredential();
18009
+ await refreshGenericMcpConfigAtRuntime(
18010
+ process.cwd(),
18011
+ resolved.effective,
18012
+ resolved.anonKey
18013
+ );
18014
+ } catch {
18015
+ }
18016
+ }
17735
18017
  return { claimResult: result.claimResult };
17736
18018
  }
17737
18019
  return null;
@@ -18608,7 +18890,7 @@ function getStringFromEnv(key) {
18608
18890
  }
18609
18891
 
18610
18892
  // ../../node_modules/@opentelemetry/core/build/esm/version.js
18611
- var VERSION2 = "2.6.1";
18893
+ var VERSION2 = "2.7.0";
18612
18894
 
18613
18895
  // ../../node_modules/@opentelemetry/semantic-conventions/build/esm/stable_attributes.js
18614
18896
  var ATTR_EXCEPTION_MESSAGE = "exception.message";
@@ -18772,6 +19054,9 @@ function mergeTwoObjects(one, two, level = 0, objects) {
18772
19054
  const keys = Object.keys(two);
18773
19055
  for (let i = 0, j = keys.length; i < j; i++) {
18774
19056
  const key = keys[i];
19057
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
19058
+ continue;
19059
+ }
18775
19060
  result[key] = takeValue(two[key]);
18776
19061
  }
18777
19062
  }
@@ -18784,6 +19069,9 @@ function mergeTwoObjects(one, two, level = 0, objects) {
18784
19069
  const keys = Object.keys(two);
18785
19070
  for (let i = 0, j = keys.length; i < j; i++) {
18786
19071
  const key = keys[i];
19072
+ if (key === "__proto__" || key === "constructor" || key === "prototype") {
19073
+ continue;
19074
+ }
18787
19075
  const twoValue = two[key];
18788
19076
  if (isPrimitive(twoValue)) {
18789
19077
  if (typeof twoValue === "undefined") {
@@ -18995,95 +19283,6 @@ function createOtlpExportDelegate(components, settings) {
18995
19283
  return new OTLPExportDelegate(components.transport, components.serializer, createLoggingPartialSuccessResponseHandler(), components.promiseHandler, settings.timeout);
18996
19284
  }
18997
19285
 
18998
- // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/common/internal.js
18999
- function createResource(resource, encoder) {
19000
- const result = {
19001
- attributes: toAttributes(resource.attributes, encoder),
19002
- droppedAttributesCount: 0
19003
- };
19004
- const schemaUrl = resource.schemaUrl;
19005
- if (schemaUrl && schemaUrl !== "")
19006
- result.schemaUrl = schemaUrl;
19007
- return result;
19008
- }
19009
- function createInstrumentationScope(scope) {
19010
- return {
19011
- name: scope.name,
19012
- version: scope.version
19013
- };
19014
- }
19015
- function toAttributes(attributes, encoder) {
19016
- return Object.keys(attributes).map((key) => toKeyValue(key, attributes[key], encoder));
19017
- }
19018
- function toKeyValue(key, value, encoder) {
19019
- return {
19020
- key,
19021
- value: toAnyValue(value, encoder)
19022
- };
19023
- }
19024
- function toAnyValue(value, encoder) {
19025
- const t = typeof value;
19026
- if (t === "string")
19027
- return { stringValue: value };
19028
- if (t === "number") {
19029
- if (!Number.isInteger(value))
19030
- return { doubleValue: value };
19031
- return { intValue: value };
19032
- }
19033
- if (t === "boolean")
19034
- return { boolValue: value };
19035
- if (value instanceof Uint8Array)
19036
- return { bytesValue: encoder.encodeUint8Array(value) };
19037
- if (Array.isArray(value)) {
19038
- const values = new Array(value.length);
19039
- for (let i = 0; i < value.length; i++) {
19040
- values[i] = toAnyValue(value[i], encoder);
19041
- }
19042
- return { arrayValue: { values } };
19043
- }
19044
- if (t === "object" && value != null) {
19045
- const keys = Object.keys(value);
19046
- const values = new Array(keys.length);
19047
- for (let i = 0; i < keys.length; i++) {
19048
- values[i] = {
19049
- key: keys[i],
19050
- value: toAnyValue(value[keys[i]], encoder)
19051
- };
19052
- }
19053
- return { kvlistValue: { values } };
19054
- }
19055
- return {};
19056
- }
19057
-
19058
- // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/common/utils.js
19059
- function hrTimeToNanos(hrTime2) {
19060
- const NANOSECONDS = BigInt(1e9);
19061
- return BigInt(Math.trunc(hrTime2[0])) * NANOSECONDS + BigInt(Math.trunc(hrTime2[1]));
19062
- }
19063
- function encodeAsString(hrTime2) {
19064
- const nanos = hrTimeToNanos(hrTime2);
19065
- return nanos.toString();
19066
- }
19067
- var encodeTimestamp = typeof BigInt !== "undefined" ? encodeAsString : hrTimeToNanoseconds;
19068
- function identity(value) {
19069
- return value;
19070
- }
19071
- var JSON_ENCODER = {
19072
- encodeHrTime: encodeTimestamp,
19073
- encodeSpanContext: identity,
19074
- encodeOptionalSpanContext: identity,
19075
- encodeUint8Array: (bytes) => {
19076
- if (typeof Buffer !== "undefined") {
19077
- return Buffer.from(bytes).toString("base64");
19078
- }
19079
- const chars = new Array(bytes.length);
19080
- for (let i = 0; i < bytes.length; i++) {
19081
- chars[i] = String.fromCharCode(bytes[i]);
19082
- }
19083
- return btoa(chars.join(""));
19084
- }
19085
- };
19086
-
19087
19286
  // ../../node_modules/@opentelemetry/resources/build/esm/ResourceImpl.js
19088
19287
  init_esm();
19089
19288
 
@@ -19228,6 +19427,95 @@ function mergeSchemaUrl(old, updating) {
19228
19427
  return void 0;
19229
19428
  }
19230
19429
 
19430
+ // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/common/internal.js
19431
+ function createResource(resource, encoder) {
19432
+ const result = {
19433
+ attributes: toAttributes(resource.attributes, encoder),
19434
+ droppedAttributesCount: 0
19435
+ };
19436
+ const schemaUrl = resource.schemaUrl;
19437
+ if (schemaUrl && schemaUrl !== "")
19438
+ result.schemaUrl = schemaUrl;
19439
+ return result;
19440
+ }
19441
+ function createInstrumentationScope(scope) {
19442
+ return {
19443
+ name: scope.name,
19444
+ version: scope.version
19445
+ };
19446
+ }
19447
+ function toAttributes(attributes, encoder) {
19448
+ return Object.keys(attributes).map((key) => toKeyValue(key, attributes[key], encoder));
19449
+ }
19450
+ function toKeyValue(key, value, encoder) {
19451
+ return {
19452
+ key,
19453
+ value: toAnyValue(value, encoder)
19454
+ };
19455
+ }
19456
+ function toAnyValue(value, encoder) {
19457
+ const t = typeof value;
19458
+ if (t === "string")
19459
+ return { stringValue: value };
19460
+ if (t === "number") {
19461
+ if (!Number.isInteger(value))
19462
+ return { doubleValue: value };
19463
+ return { intValue: value };
19464
+ }
19465
+ if (t === "boolean")
19466
+ return { boolValue: value };
19467
+ if (value instanceof Uint8Array)
19468
+ return { bytesValue: encoder.encodeUint8Array(value) };
19469
+ if (Array.isArray(value)) {
19470
+ const values = new Array(value.length);
19471
+ for (let i = 0; i < value.length; i++) {
19472
+ values[i] = toAnyValue(value[i], encoder);
19473
+ }
19474
+ return { arrayValue: { values } };
19475
+ }
19476
+ if (t === "object" && value != null) {
19477
+ const keys = Object.keys(value);
19478
+ const values = new Array(keys.length);
19479
+ for (let i = 0; i < keys.length; i++) {
19480
+ values[i] = {
19481
+ key: keys[i],
19482
+ value: toAnyValue(value[keys[i]], encoder)
19483
+ };
19484
+ }
19485
+ return { kvlistValue: { values } };
19486
+ }
19487
+ return {};
19488
+ }
19489
+
19490
+ // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/common/utils.js
19491
+ function hrTimeToNanos(hrTime2) {
19492
+ const NANOSECONDS = BigInt(1e9);
19493
+ return BigInt(Math.trunc(hrTime2[0])) * NANOSECONDS + BigInt(Math.trunc(hrTime2[1]));
19494
+ }
19495
+ function encodeAsString(hrTime2) {
19496
+ const nanos = hrTimeToNanos(hrTime2);
19497
+ return nanos.toString();
19498
+ }
19499
+ var encodeTimestamp = typeof BigInt !== "undefined" ? encodeAsString : hrTimeToNanoseconds;
19500
+ function identity(value) {
19501
+ return value;
19502
+ }
19503
+ var JSON_ENCODER = {
19504
+ encodeHrTime: encodeTimestamp,
19505
+ encodeSpanContext: identity,
19506
+ encodeOptionalSpanContext: identity,
19507
+ encodeUint8Array: (bytes) => {
19508
+ if (typeof Buffer !== "undefined") {
19509
+ return Buffer.from(bytes).toString("base64");
19510
+ }
19511
+ const chars = new Array(bytes.length);
19512
+ for (let i = 0; i < bytes.length; i++) {
19513
+ chars[i] = String.fromCharCode(bytes[i]);
19514
+ }
19515
+ return btoa(chars.join(""));
19516
+ }
19517
+ };
19518
+
19231
19519
  // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/trace/internal.js
19232
19520
  var SPAN_FLAGS_CONTEXT_HAS_IS_REMOTE_MASK = 256;
19233
19521
  var SPAN_FLAGS_CONTEXT_IS_REMOTE_MASK = 512;
@@ -19342,6 +19630,7 @@ function spanRecordsToResourceSpans(readableSpans, encoder) {
19342
19630
  }
19343
19631
 
19344
19632
  // ../../node_modules/@opentelemetry/otlp-transformer/build/esm/trace/json/trace.js
19633
+ init_esm();
19345
19634
  var JsonTraceSerializer = {
19346
19635
  serializeRequest: (arg) => {
19347
19636
  const request = createExportTraceServiceRequest(arg, JSON_ENCODER);
@@ -19353,7 +19642,12 @@ var JsonTraceSerializer = {
19353
19642
  return {};
19354
19643
  }
19355
19644
  const decoder = new TextDecoder();
19356
- return JSON.parse(decoder.decode(arg));
19645
+ try {
19646
+ return JSON.parse(decoder.decode(arg));
19647
+ } catch (err) {
19648
+ diag2.warn(`Failed to parse trace export response: ${err.message}. Returning empty response`);
19649
+ return {};
19650
+ }
19357
19651
  }
19358
19652
  };
19359
19653
 
@@ -19464,10 +19758,11 @@ function parseRetryAfterToMills(retryAfter) {
19464
19758
  }
19465
19759
 
19466
19760
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/version.js
19467
- var VERSION3 = "0.214.0";
19761
+ var VERSION3 = "0.215.0";
19468
19762
 
19469
19763
  // ../../node_modules/@opentelemetry/otlp-exporter-base/build/esm/transport/http-transport-utils.js
19470
19764
  var DEFAULT_USER_AGENT = `OTel-OTLP-Exporter-JavaScript/${VERSION3}`;
19765
+ var MAX_RESPONSE_BODY_SIZE = 4 * 1024 * 1024;
19471
19766
  function sendWithHttp(request, url2, headers, compression, userAgent, agent, data, timeoutMillis) {
19472
19767
  return new Promise((resolve3) => {
19473
19768
  const parsedUrl = new URL(url2);
@@ -19486,7 +19781,17 @@ function sendWithHttp(request, url2, headers, compression, userAgent, agent, dat
19486
19781
  };
19487
19782
  const req = request(options, (res) => {
19488
19783
  const responseData = [];
19489
- res.on("data", (chunk) => responseData.push(chunk));
19784
+ let responseSize = 0;
19785
+ res.on("data", (chunk) => {
19786
+ responseSize += chunk.length;
19787
+ if (responseSize > MAX_RESPONSE_BODY_SIZE) {
19788
+ const sizeError = new Error(`OTLP export response body exceeded size limit of ${MAX_RESPONSE_BODY_SIZE} bytes`);
19789
+ resolve3({ status: "failure", error: sizeError });
19790
+ res.destroy();
19791
+ return;
19792
+ }
19793
+ responseData.push(chunk);
19794
+ });
19490
19795
  res.on("end", () => {
19491
19796
  if (res.statusCode && res.statusCode <= 299) {
19492
19797
  resolve3({
@@ -20689,7 +20994,7 @@ function samplingDecisionToString(decision) {
20689
20994
  }
20690
20995
 
20691
20996
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/version.js
20692
- var VERSION4 = "2.6.1";
20997
+ var VERSION4 = "2.7.0";
20693
20998
 
20694
20999
  // ../../node_modules/@opentelemetry/sdk-trace-base/build/esm/Tracer.js
20695
21000
  var Tracer = class {
@@ -21456,24 +21761,24 @@ function detectSentry() {
21456
21761
  }
21457
21762
 
21458
21763
  // src/otel-config.ts
21459
- var _resolvedApiKey = API_KEY_PENDING;
21460
- var _activeExporter = null;
21461
- var _additionalExporters = [];
21462
- var _injectedProcessor = null;
21764
+ var resolvedApiKey = API_KEY_PENDING;
21765
+ var activeExporter = null;
21766
+ var additionalExporters = [];
21767
+ var injectedProcessor = null;
21463
21768
  function setResolvedApiKey(key) {
21464
- _resolvedApiKey = key;
21769
+ resolvedApiKey = key;
21465
21770
  }
21466
21771
  function getResolvedApiKey() {
21467
- return _resolvedApiKey;
21772
+ return resolvedApiKey;
21468
21773
  }
21469
21774
  function notifyApiKeyResolved() {
21470
- _activeExporter?.notifyKeyResolved();
21471
- for (const exporter of _additionalExporters) {
21775
+ activeExporter?.notifyKeyResolved();
21776
+ for (const exporter of additionalExporters) {
21472
21777
  exporter.notifyKeyResolved();
21473
21778
  }
21474
21779
  }
21475
21780
  function registerExporterForKeyNotification(exporter) {
21476
- _additionalExporters.push(exporter);
21781
+ additionalExporters.push(exporter);
21477
21782
  }
21478
21783
  async function tryImport(moduleId) {
21479
21784
  try {
@@ -21516,7 +21821,7 @@ async function runCoexistencePath(existingProvider, config2) {
21516
21821
  return;
21517
21822
  }
21518
21823
  if (result !== null) {
21519
- _injectedProcessor = result.processor;
21824
+ injectedProcessor = result.processor;
21520
21825
  if (config2.verbose) {
21521
21826
  sdkLog(
21522
21827
  "info",
@@ -21527,8 +21832,8 @@ async function runCoexistencePath(existingProvider, config2) {
21527
21832
  name: "coexistence-flush",
21528
21833
  priority: 5,
21529
21834
  fn: async () => {
21530
- if (_injectedProcessor) {
21531
- await _injectedProcessor.forceFlush();
21835
+ if (injectedProcessor) {
21836
+ await injectedProcessor.forceFlush();
21532
21837
  }
21533
21838
  }
21534
21839
  });
@@ -21564,7 +21869,7 @@ async function runRegistrationPath(config2, sessionManager) {
21564
21869
  createDelegate: createOtlpExporter,
21565
21870
  verbose: config2.verbose
21566
21871
  });
21567
- _activeExporter = glasstraceExporter;
21872
+ activeExporter = glasstraceExporter;
21568
21873
  const vercelOtel = await tryImport("@vercel/otel");
21569
21874
  if (vercelOtel && typeof vercelOtel.registerOTel === "function") {
21570
21875
  const otelConfig = {
@@ -21897,7 +22202,7 @@ function registerGlasstrace(options) {
21897
22202
  setCoreState(CoreState.REGISTERING);
21898
22203
  startRuntimeStateWriter({
21899
22204
  projectRoot: process.cwd(),
21900
- sdkVersion: "1.0.1"
22205
+ sdkVersion: "1.1.1"
21901
22206
  });
21902
22207
  const config2 = resolveConfig(options);
21903
22208
  if (config2.verbose) {
@@ -22063,8 +22368,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22063
22368
  if (config2.verbose) {
22064
22369
  console.info("[glasstrace] Background init firing.");
22065
22370
  }
22066
- const healthReport = collectHealthReport("1.0.1");
22067
- const initResult = await performInit(config2, anonKeyForInit, "1.0.1", healthReport);
22371
+ const healthReport = collectHealthReport("1.1.1");
22372
+ const initResult = await performInit(config2, anonKeyForInit, "1.1.1", healthReport);
22068
22373
  if (generation !== registrationGeneration) return;
22069
22374
  const currentState = getCoreState();
22070
22375
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -22087,7 +22392,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
22087
22392
  }
22088
22393
  maybeInstallConsoleCapture();
22089
22394
  if (didLastInitSucceed()) {
22090
- startHeartbeat(config2, anonKeyForInit, "1.0.1", generation, (newApiKey, accountId) => {
22395
+ startHeartbeat(config2, anonKeyForInit, "1.1.1", generation, (newApiKey, accountId) => {
22091
22396
  setAuthState(AuthState.CLAIMING);
22092
22397
  emitLifecycleEvent("auth:claim_started", { accountId });
22093
22398
  setResolvedApiKey(newApiKey);