@glasstrace/sdk 1.17.0 → 1.18.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 (35) hide show
  1. package/dist/{capture-error-B0txjNut.d.cts → capture-error-B8qiXFeC.d.cts} +2 -2
  2. package/dist/{capture-error-Dc01rYNR.d.ts → capture-error-BTI6mCH2.d.ts} +2 -2
  3. package/dist/{chunk-VEQX2YSQ.js → chunk-SONZOTBP.js} +9 -1
  4. package/dist/{chunk-VEQX2YSQ.js.map → chunk-SONZOTBP.js.map} +1 -1
  5. package/dist/{chunk-F2IPBTDJ.js → chunk-Z2DSC3YI.js} +20 -8
  6. package/dist/{chunk-F2IPBTDJ.js.map → chunk-Z2DSC3YI.js.map} +1 -1
  7. package/dist/cli/init.cjs +4 -4
  8. package/dist/cli/init.cjs.map +1 -1
  9. package/dist/cli/init.js +3 -3
  10. package/dist/cli/mcp-add.cjs +1 -1
  11. package/dist/cli/mcp-add.js +1 -1
  12. package/dist/cli/upgrade-instructions.cjs +1 -1
  13. package/dist/cli/upgrade-instructions.js +1 -1
  14. package/dist/{correlation-id-CelUvw7j.d.cts → correlation-id-CClOq8Wn.d.cts} +1 -1
  15. package/dist/{correlation-id-B9YYmoZw.d.ts → correlation-id-Ct86Ug4s.d.ts} +1 -1
  16. package/dist/edge-entry.d.cts +2 -2
  17. package/dist/edge-entry.d.ts +2 -2
  18. package/dist/{import-graph-Dka_Fm7j.d.ts → import-graph-DZjTJdJ5.d.ts} +1 -1
  19. package/dist/{import-graph-DBLGNjcI.d.cts → import-graph-DyQfZU2f.d.cts} +1 -1
  20. package/dist/index.cjs +136 -6
  21. package/dist/index.cjs.map +1 -1
  22. package/dist/{index.d-3-cJoY8y.d.cts → index.d-DhatN7mq.d.cts} +1 -1
  23. package/dist/{index.d-3-cJoY8y.d.ts → index.d-DhatN7mq.d.ts} +1 -1
  24. package/dist/index.d.cts +170 -5
  25. package/dist/index.d.ts +170 -5
  26. package/dist/index.js +123 -3
  27. package/dist/index.js.map +1 -1
  28. package/dist/node-entry.cjs +5 -5
  29. package/dist/node-entry.cjs.map +1 -1
  30. package/dist/node-entry.d.cts +4 -4
  31. package/dist/node-entry.d.ts +4 -4
  32. package/dist/node-entry.js +2 -2
  33. package/dist/node-subpath.d.cts +2 -2
  34. package/dist/node-subpath.d.ts +2 -2
  35. package/package.json +1 -1
package/dist/cli/init.js CHANGED
@@ -4,7 +4,7 @@ import {
4
4
  } from "../chunk-2M57EO6U.js";
5
5
  import {
6
6
  verifyInitReachable
7
- } from "../chunk-VEQX2YSQ.js";
7
+ } from "../chunk-SONZOTBP.js";
8
8
  import {
9
9
  buildImportGraph
10
10
  } from "../chunk-M3QGJUEI.js";
@@ -918,7 +918,7 @@ Then add this as the first statement in your register() function:
918
918
  );
919
919
  const dispatchSet = detectedNonGeneric.length === 0 ? agentsWithMcpReady : nonGenericReady;
920
920
  if (dispatchSet.length > 0) {
921
- const sdkVersionForInject = true ? "1.17.0" : "0.0.0-dev";
921
+ const sdkVersionForInject = true ? "1.18.0" : "0.0.0-dev";
922
922
  try {
923
923
  await injectAllTargets(
924
924
  dispatchSet,
@@ -1020,7 +1020,7 @@ async function verifyAnonKeyRegistration(projectRoot) {
1020
1020
  }
1021
1021
  const baseConfig = resolveConfig({ apiKey: devKey });
1022
1022
  const config = { ...baseConfig, apiKey: devKey };
1023
- const sdkVersion = true ? "1.17.0" : "0.0.0-dev";
1023
+ const sdkVersion = true ? "1.18.0" : "0.0.0-dev";
1024
1024
  const result = await verifyInitReachable(config, anonKey, sdkVersion);
1025
1025
  if (result.ok) {
1026
1026
  return { outcome: "verified" };
@@ -16003,7 +16003,7 @@ async function mcpAdd(options) {
16003
16003
  );
16004
16004
  const dispatchSetMcpAdd = detectedNonGenericMcpAdd.length === 0 ? agentsWithMcpReady : nonGenericReadyMcpAdd;
16005
16005
  if (dispatchSetMcpAdd.length > 0) {
16006
- const sdkVersion = true ? "1.17.0" : "0.0.0-dev";
16006
+ const sdkVersion = true ? "1.18.0" : "0.0.0-dev";
16007
16007
  try {
16008
16008
  await injectAllTargets(
16009
16009
  dispatchSetMcpAdd,
@@ -230,7 +230,7 @@ async function mcpAdd(options) {
230
230
  );
231
231
  const dispatchSetMcpAdd = detectedNonGenericMcpAdd.length === 0 ? agentsWithMcpReady : nonGenericReadyMcpAdd;
232
232
  if (dispatchSetMcpAdd.length > 0) {
233
- const sdkVersion = true ? "1.17.0" : "0.0.0-dev";
233
+ const sdkVersion = true ? "1.18.0" : "0.0.0-dev";
234
234
  try {
235
235
  await injectAllTargets(
236
236
  dispatchSetMcpAdd,
@@ -672,7 +672,7 @@ async function runUpgradeInstructions(options) {
672
672
  );
673
673
  return { exitCode: 1, refreshed, skipped, warnings, errors };
674
674
  }
675
- const sdkVersion = true ? "1.17.0" : "0.0.0-dev";
675
+ const sdkVersion = true ? "1.18.0" : "0.0.0-dev";
676
676
  const optedInAgents = [];
677
677
  for (const agent of agents) {
678
678
  if (agent.infoFilePath === null) {
@@ -67,7 +67,7 @@ async function runUpgradeInstructions(options) {
67
67
  );
68
68
  return { exitCode: 1, refreshed, skipped, warnings, errors };
69
69
  }
70
- const sdkVersion = true ? "1.17.0" : "0.0.0-dev";
70
+ const sdkVersion = true ? "1.18.0" : "0.0.0-dev";
71
71
  const optedInAgents = [];
72
72
  for (const agent of agents) {
73
73
  if (agent.infoFilePath === null) {
@@ -1,4 +1,4 @@
1
- import { j as SdkDiagnosticCode, k as SessionId, C as CaptureConfig } from './index.d-3-cJoY8y.cjs';
1
+ import { j as SdkDiagnosticCode, k as SessionId, C as CaptureConfig } from './index.d-DhatN7mq.cjs';
2
2
  import { ReadableSpan } from './export/ReadableSpan';
3
3
  import { Span } from './Span';
4
4
  import { SpanProcessor } from './SpanProcessor';
@@ -1,4 +1,4 @@
1
- import { j as SdkDiagnosticCode, k as SessionId, C as CaptureConfig } from './index.d-3-cJoY8y.js';
1
+ import { j as SdkDiagnosticCode, k as SessionId, C as CaptureConfig } from './index.d-DhatN7mq.js';
2
2
  import { ReadableSpan } from './export/ReadableSpan';
3
3
  import { Span } from './Span';
4
4
  import { SpanProcessor } from './SpanProcessor';
@@ -1,7 +1,7 @@
1
- export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-CelUvw7j.cjs';
1
+ export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-CClOq8Wn.cjs';
2
2
  export { RequestMiddlewareFunction, TracedRequestMiddlewareOptions, tracedRequestMiddleware } from './middleware/index.cjs';
3
3
  export { WithAsyncCausalityOptions, withAsyncCausality } from './async-context/index.cjs';
4
- import './index.d-3-cJoY8y.cjs';
4
+ import './index.d-DhatN7mq.cjs';
5
5
  import './v4/classic/external.cjs';
6
6
  import './export/ReadableSpan';
7
7
  import './Span';
@@ -1,7 +1,7 @@
1
- export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-B9YYmoZw.js';
1
+ export { C as CorrelationIdRequest, G as GlasstraceSpanProcessor, S as SdkError, c as captureCorrelationId } from './correlation-id-Ct86Ug4s.js';
2
2
  export { RequestMiddlewareFunction, TracedRequestMiddlewareOptions, tracedRequestMiddleware } from './middleware/index.js';
3
3
  export { WithAsyncCausalityOptions, withAsyncCausality } from './async-context/index.js';
4
- import './index.d-3-cJoY8y.js';
4
+ import './index.d-DhatN7mq.js';
5
5
  import './v4/classic/external.cjs';
6
6
  import './export/ReadableSpan';
7
7
  import './Span';
@@ -1,4 +1,4 @@
1
- import { g as SourceMapUploadResponse, h as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-3-cJoY8y.js';
1
+ import { S as SourceMapUploadResponse, a as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-DhatN7mq.js';
2
2
 
3
3
  /**
4
4
  * In-memory source map entry: a file path paired with its full text content.
@@ -1,4 +1,4 @@
1
- import { g as SourceMapUploadResponse, h as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-3-cJoY8y.cjs';
1
+ import { S as SourceMapUploadResponse, a as SourceMapManifestResponse, I as ImportGraphPayload } from './index.d-DhatN7mq.cjs';
2
2
 
3
3
  /**
4
4
  * In-memory source map entry: a file path paired with its full text content.
package/dist/index.cjs CHANGED
@@ -17918,6 +17918,7 @@ __export(src_exports, {
17918
17918
  GlasstraceSpanProcessor: () => GlasstraceSpanProcessor,
17919
17919
  SdkError: () => SdkError,
17920
17920
  SessionManager: () => SessionManager,
17921
+ capture: () => capture,
17921
17922
  captureCorrelationId: () => captureCorrelationId,
17922
17923
  captureError: () => captureError,
17923
17924
  classifyFetchTarget: () => classifyFetchTarget,
@@ -17938,6 +17939,7 @@ __export(src_exports, {
17938
17939
  isSideEffectSemanticFieldKey: () => isSideEffectSemanticFieldKey,
17939
17940
  loadCachedConfig: () => loadCachedConfig,
17940
17941
  performInit: () => performInit,
17942
+ prismaAdapter: () => prismaAdapter,
17941
17943
  readAnonKey: () => readAnonKey,
17942
17944
  readEnvVars: () => readEnvVars,
17943
17945
  recordSideEffect: () => recordSideEffect,
@@ -19272,6 +19274,13 @@ function getActiveConfig() {
19272
19274
  }
19273
19275
  return { ...DEFAULT_CAPTURE_CONFIG };
19274
19276
  }
19277
+ function isCaptureEnabled() {
19278
+ try {
19279
+ return getActiveConfig().sideEffectEvidence === true;
19280
+ } catch {
19281
+ return false;
19282
+ }
19283
+ }
19275
19284
  function getLinkedAccountId() {
19276
19285
  return currentConfig?.linkedAccountId;
19277
19286
  }
@@ -24307,7 +24316,7 @@ var spanState = /* @__PURE__ */ new WeakMap();
24307
24316
  function getOrCreateState(span) {
24308
24317
  let state = spanState.get(span);
24309
24318
  if (!state) {
24310
- state = { operationsRecorded: 0, omissions: /* @__PURE__ */ new Map() };
24319
+ state = { operationsRecorded: 0, omissions: /* @__PURE__ */ new Map(), scalarsRecorded: 0 };
24311
24320
  spanState.set(span, state);
24312
24321
  }
24313
24322
  return state;
@@ -24420,6 +24429,14 @@ function attachScalar(span, key, value) {
24420
24429
  } catch {
24421
24430
  }
24422
24431
  }
24432
+ function reserveScalarSlot(span) {
24433
+ const state = getOrCreateState(span);
24434
+ if (state.scalarsRecorded >= MAX_SIDE_EFFECT_SCALARS_PER_OPERATION) {
24435
+ return false;
24436
+ }
24437
+ state.scalarsRecorded += 1;
24438
+ return true;
24439
+ }
24423
24440
  function recordOmission(span, reason) {
24424
24441
  recordOmissionOnSpan(span, reason);
24425
24442
  }
@@ -24903,11 +24920,11 @@ function registerGlasstrace(options) {
24903
24920
  setCoreState(CoreState.REGISTERING);
24904
24921
  maybeWarnStaleAgentInstructions({
24905
24922
  projectRoot: process.cwd(),
24906
- sdkVersion: "1.17.0"
24923
+ sdkVersion: "1.18.0"
24907
24924
  });
24908
24925
  startRuntimeStateWriter({
24909
24926
  projectRoot: process.cwd(),
24910
- sdkVersion: "1.17.0"
24927
+ sdkVersion: "1.18.0"
24911
24928
  });
24912
24929
  const config2 = resolveConfig(options);
24913
24930
  setSideEffectVerboseFlag(config2.verbose);
@@ -25075,8 +25092,8 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
25075
25092
  if (config2.verbose) {
25076
25093
  console.info("[glasstrace] Background init firing.");
25077
25094
  }
25078
- const healthReport = collectHealthReport("1.17.0");
25079
- const initResult = await performInit(config2, anonKeyForInit, "1.17.0", healthReport);
25095
+ const healthReport = collectHealthReport("1.18.0");
25096
+ const initResult = await performInit(config2, anonKeyForInit, "1.18.0", healthReport);
25080
25097
  if (generation !== registrationGeneration) return;
25081
25098
  const currentState = getCoreState();
25082
25099
  if (currentState === CoreState.SHUTTING_DOWN || currentState === CoreState.SHUTDOWN) {
@@ -25099,7 +25116,7 @@ async function backgroundInit(config2, anonKeyForInit, generation) {
25099
25116
  }
25100
25117
  maybeInstallConsoleCapture();
25101
25118
  if (didLastInitSucceed()) {
25102
- startHeartbeat(config2, anonKeyForInit, "1.17.0", generation, (newApiKey, accountId) => {
25119
+ startHeartbeat(config2, anonKeyForInit, "1.18.0", generation, (newApiKey, accountId) => {
25103
25120
  setAuthState(AuthState.CLAIMING);
25104
25121
  emitLifecycleEvent("auth:claim_started", { accountId });
25105
25122
  setResolvedApiKey(newApiKey);
@@ -25392,6 +25409,117 @@ function firstToken(value) {
25392
25409
  return void 0;
25393
25410
  }
25394
25411
 
25412
+ // src/side-effect/capture.ts
25413
+ function capture(name, value, options) {
25414
+ try {
25415
+ runCapture(name, value, options);
25416
+ } catch {
25417
+ }
25418
+ }
25419
+ function runCapture(name, value, options) {
25420
+ const span = options?.span;
25421
+ if (!span) return;
25422
+ if (!isCaptureEnabled()) return;
25423
+ try {
25424
+ if (typeof span.isRecording === "function" && !span.isRecording()) {
25425
+ return;
25426
+ }
25427
+ } catch {
25428
+ return;
25429
+ }
25430
+ const outcome = checkScalarField(name, value);
25431
+ if (!outcome.accepted) {
25432
+ recordOmission(span, outcome.reason);
25433
+ return;
25434
+ }
25435
+ if (!reserveScalarSlot(span)) {
25436
+ recordOmission(span, "value_too_long");
25437
+ return;
25438
+ }
25439
+ attachScalar(span, name, outcome.value);
25440
+ }
25441
+
25442
+ // src/adapters/prisma.ts
25443
+ init_esm();
25444
+ var TRACER_NAME = "glasstrace-prisma";
25445
+ function hasRecordingActiveSpan() {
25446
+ try {
25447
+ const span = trace.getActiveSpan();
25448
+ if (span === void 0) return false;
25449
+ if (typeof span.isRecording === "function" && !span.isRecording()) {
25450
+ return false;
25451
+ }
25452
+ return true;
25453
+ } catch {
25454
+ return false;
25455
+ }
25456
+ }
25457
+ function openOwnedSpan(model, operation) {
25458
+ try {
25459
+ return trace.getTracer(TRACER_NAME).startSpan(`db.${model}.${operation}`, { kind: SpanKind.CLIENT });
25460
+ } catch {
25461
+ return void 0;
25462
+ }
25463
+ }
25464
+ function deriveFlagKey(column) {
25465
+ return column.endsWith("Flag") ? column : `${column}Flag`;
25466
+ }
25467
+ function projectAllowlisted(span, columns, result) {
25468
+ if (result === null || typeof result !== "object" || Array.isArray(result)) {
25469
+ return;
25470
+ }
25471
+ const row = result;
25472
+ for (const column of columns) {
25473
+ if (!(column in row)) continue;
25474
+ capture(deriveFlagKey(column), row[column], { span });
25475
+ }
25476
+ }
25477
+ function prismaAdapter(options = {}) {
25478
+ const policy = /* @__PURE__ */ new Map();
25479
+ for (const entry of options?.allow ?? []) {
25480
+ if (!entry || typeof entry.model !== "string" || typeof entry.column !== "string" || entry.model.length === 0 || entry.column.length === 0) {
25481
+ continue;
25482
+ }
25483
+ let columns = policy.get(entry.model);
25484
+ if (!columns) {
25485
+ columns = /* @__PURE__ */ new Set();
25486
+ policy.set(entry.model, columns);
25487
+ }
25488
+ columns.add(entry.column);
25489
+ }
25490
+ return {
25491
+ name: "glasstrace-capture",
25492
+ query: {
25493
+ $allModels: {
25494
+ async $allOperations(params) {
25495
+ const { model, operation, args, query } = params;
25496
+ const columns = model !== void 0 ? policy.get(model) : void 0;
25497
+ if (model === void 0 || columns === void 0 || operation === "findMany" || !isCaptureEnabled() || !hasRecordingActiveSpan()) {
25498
+ return query(args);
25499
+ }
25500
+ const span = openOwnedSpan(model, operation);
25501
+ if (span === void 0) {
25502
+ return query(args);
25503
+ }
25504
+ try {
25505
+ const result = await query(args);
25506
+ try {
25507
+ projectAllowlisted(span, columns, result);
25508
+ } catch {
25509
+ }
25510
+ return result;
25511
+ } finally {
25512
+ try {
25513
+ span.end();
25514
+ } catch {
25515
+ }
25516
+ }
25517
+ }
25518
+ }
25519
+ }
25520
+ };
25521
+ }
25522
+
25395
25523
  // src/side-effect/invariant.ts
25396
25524
  function invariant(left, op, right) {
25397
25525
  switch (op) {
@@ -25423,6 +25551,7 @@ init_dist();
25423
25551
  GlasstraceSpanProcessor,
25424
25552
  SdkError,
25425
25553
  SessionManager,
25554
+ capture,
25426
25555
  captureCorrelationId,
25427
25556
  captureError,
25428
25557
  classifyFetchTarget,
@@ -25443,6 +25572,7 @@ init_dist();
25443
25572
  isSideEffectSemanticFieldKey,
25444
25573
  loadCachedConfig,
25445
25574
  performInit,
25575
+ prismaAdapter,
25446
25576
  readAnonKey,
25447
25577
  readEnvVars,
25448
25578
  recordSideEffect,