repro-nest 0.0.207 → 0.0.208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -29,6 +29,11 @@ type TracerApi = {
29
29
  init?: (opts: any) => void;
30
30
  tracer?: {
31
31
  on: (fn: (ev: any) => void) => () => void;
32
+ getCurrentTraceContext?: () => {
33
+ traceId: any;
34
+ spanId: any;
35
+ depth?: number;
36
+ };
32
37
  };
33
38
  getCurrentTraceId?: () => string | null;
34
39
  patchHttp?: () => void;
package/dist/index.js CHANGED
@@ -439,6 +439,13 @@ function initReproTracing(opts) {
439
439
  const initOpts = { ...defaultTracerInitOpts(), ...rest };
440
440
  tracerPkg.init?.(initOpts);
441
441
  tracerPkg.patchHttp?.();
442
+ // Ensure tracer exposes current trace context on the on-event API when available.
443
+ try {
444
+ if (!tracerPkg.tracer?.getCurrentTraceContext && tracerPkg.getCurrentTraceContext) {
445
+ tracerPkg.tracer.getCurrentTraceContext = tracerPkg.getCurrentTraceContext;
446
+ }
447
+ }
448
+ catch { }
442
449
  applyTraceLogPreference(tracerPkg);
443
450
  __TRACER_READY = true;
444
451
  patchAllKnownMongooseInstances();
@@ -800,7 +807,8 @@ const SESSION_DRAIN_TIMEOUT_MS = (() => {
800
807
  if (Number.isFinite(env) && env >= 0)
801
808
  return env;
802
809
  // Bound wait for draining sessions to avoid lost flushes when a request hangs.
803
- return 10000;
810
+ // Default to 1 minute; caller can override via env.
811
+ return 60000;
804
812
  })();
805
813
  function isThenable(value) {
806
814
  return value != null && typeof value === 'object' && typeof value.then === 'function';
@@ -1891,6 +1899,12 @@ function dehydrateComplexValue(value) {
1891
1899
  function emitDbQuery(cfg, sid, aid, payload) {
1892
1900
  if (!sid)
1893
1901
  return;
1902
+ let traceCtx = null;
1903
+ try {
1904
+ const getCtx = __TRACER__?.tracer?.getCurrentTraceContext;
1905
+ traceCtx = typeof getCtx === 'function' ? getCtx() : null;
1906
+ }
1907
+ catch { }
1894
1908
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
1895
1909
  entries: [{
1896
1910
  actionId: aid ?? null,
@@ -1900,6 +1914,8 @@ function emitDbQuery(cfg, sid, aid, payload) {
1900
1914
  query: payload.query ?? undefined,
1901
1915
  resultMeta: payload.resultMeta ?? undefined,
1902
1916
  durMs: payload.durMs ?? undefined,
1917
+ traceId: traceCtx?.traceId ?? null,
1918
+ spanId: traceCtx?.spanId ?? null,
1903
1919
  pk: null, before: null, after: null,
1904
1920
  error: payload.error ?? undefined,
1905
1921
  }],
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "repro-nest",
3
- "version": "0.0.207",
3
+ "version": "0.0.208",
4
4
  "description": "Repro Nest SDK",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/index.ts CHANGED
@@ -174,7 +174,10 @@ function patchAllKnownMongooseInstances() {
174
174
  // ====== tiny, safe tracer auto-init (no node_modules patches) ======
175
175
  type TracerApi = {
176
176
  init?: (opts: any) => void;
177
- tracer?: { on: (fn: (ev: any) => void) => () => void };
177
+ tracer?: {
178
+ on: (fn: (ev: any) => void) => () => void;
179
+ getCurrentTraceContext?: () => { traceId: any; spanId: any; depth?: number };
180
+ };
178
181
  getCurrentTraceId?: () => string | null;
179
182
  patchHttp?: () => void; // optional in your tracer
180
183
  setFunctionLogsEnabled?: (enabled: boolean) => void;
@@ -623,6 +626,12 @@ export function initReproTracing(opts?: ReproTracingInitOptions) {
623
626
  const initOpts = { ...defaultTracerInitOpts(), ...(rest as TracerInitOpts) };
624
627
  tracerPkg.init?.(initOpts);
625
628
  tracerPkg.patchHttp?.();
629
+ // Ensure tracer exposes current trace context on the on-event API when available.
630
+ try {
631
+ if (!tracerPkg.tracer?.getCurrentTraceContext && (tracerPkg as any).getCurrentTraceContext) {
632
+ (tracerPkg.tracer as any).getCurrentTraceContext = (tracerPkg as any).getCurrentTraceContext;
633
+ }
634
+ } catch {}
626
635
  applyTraceLogPreference(tracerPkg);
627
636
  __TRACER_READY = true;
628
637
  patchAllKnownMongooseInstances();
@@ -1024,7 +1033,8 @@ const SESSION_DRAIN_TIMEOUT_MS = (() => {
1024
1033
  const env = Number(process.env.SESSION_DRAIN_TIMEOUT_MS);
1025
1034
  if (Number.isFinite(env) && env >= 0) return env;
1026
1035
  // Bound wait for draining sessions to avoid lost flushes when a request hangs.
1027
- return 10000;
1036
+ // Default to 1 minute; caller can override via env.
1037
+ return 60000;
1028
1038
  })();
1029
1039
 
1030
1040
  function isThenable(value: any): value is PromiseLike<any> {
@@ -2104,6 +2114,12 @@ function dehydrateComplexValue(value: any) {
2104
2114
 
2105
2115
  function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
2106
2116
  if (!sid) return;
2117
+ let traceCtx: { traceId: any; spanId: any } | null = null;
2118
+ try {
2119
+ const getCtx = __TRACER__?.tracer?.getCurrentTraceContext;
2120
+ traceCtx = typeof getCtx === 'function' ? getCtx() : null;
2121
+ } catch {}
2122
+
2107
2123
  post(cfg.apiBase, cfg.tenantId, cfg.appId, cfg.appSecret, sid, {
2108
2124
  entries: [{
2109
2125
  actionId: aid ?? null,
@@ -2113,6 +2129,8 @@ function emitDbQuery(cfg: any, sid?: string, aid?: string, payload?: any) {
2113
2129
  query: payload.query ?? undefined,
2114
2130
  resultMeta: payload.resultMeta ?? undefined,
2115
2131
  durMs: payload.durMs ?? undefined,
2132
+ traceId: traceCtx?.traceId ?? null,
2133
+ spanId: traceCtx?.spanId ?? null,
2116
2134
  pk: null, before: null, after: null,
2117
2135
  error: payload.error ?? undefined,
2118
2136
  }],
package/tracer/runtime.js CHANGED
@@ -100,6 +100,17 @@ function popSpan(ctx) {
100
100
  const trace = {
101
101
  on(fn){ listeners.add(fn); return () => listeners.delete(fn); },
102
102
  withTrace(id, fn, depth = 0){ return als.run({ traceId: id, depth }, fn); },
103
+ getCurrentTraceContext(){
104
+ const store = als.getStore();
105
+ if (!store) return { traceId: null, spanId: null, depth: 0 };
106
+ const spanStack = Array.isArray(store.__repro_span_stack) ? store.__repro_span_stack : [];
107
+ const top = spanStack.length ? spanStack[spanStack.length - 1] : null;
108
+ return {
109
+ traceId: store.traceId || null,
110
+ spanId: top ? top.id ?? null : null,
111
+ depth: typeof store.depth === 'number' ? store.depth : (top?.depth ?? 0),
112
+ };
113
+ },
103
114
  enter(fn, meta, detail){
104
115
  const parentSpanIdOverride = meta && Object.prototype.hasOwnProperty.call(meta, 'parentSpanId')
105
116
  ? meta.parentSpanId