@jennifersoft/jennifer5-instrumentation 5.6.5-1 → 5.6.5

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.mts CHANGED
@@ -52,37 +52,4 @@ type GcMetricsCallback = (gcCount: number, gcTime: number, gcCountDelta: number)
52
52
  */
53
53
  declare function startGcMetricsCollection(intervalMs?: number, callback?: GcMetricsCallback): (() => void) | null;
54
54
 
55
- /**
56
- * Transaction context that is maintained across async operations
57
- */
58
- interface TransactionContext {
59
- id: number;
60
- enable: boolean;
61
- }
62
- /**
63
- * Manages transaction contexts using AsyncLocalStorage
64
- */
65
- declare class TransactionContextManager {
66
- private _asyncLocalStorage;
67
- constructor();
68
- /**
69
- * Create a new transaction context
70
- */
71
- start(): TransactionContext;
72
- /**
73
- * Run a callback within a transaction context scope
74
- * All async operations within this scope will automatically have access to the context
75
- */
76
- run<T>(ctx: TransactionContext, callback: () => T): T;
77
- /**
78
- * Get the current transaction context (if any)
79
- * This works automatically across async boundaries thanks to AsyncLocalStorage
80
- */
81
- getCurrentContext(): TransactionContext | undefined;
82
- }
83
- declare const contextManager: TransactionContextManager;
84
-
85
- type RouteHandler<TRequest extends Request = Request> = (request: TRequest) => Promise<Response> | Response;
86
- declare function withJenniferNextRouteTx<TRequest extends Request>(handler: RouteHandler<TRequest>): RouteHandler<TRequest>;
87
-
88
- export { type GcMetricsCallback, type HeapMetricsCallback, type TransactionContext, TransactionContextManager, contextManager, registerIitmHooks, registerRitmHooks, startGcMetricsCollection, startHeapMetricsCollection, withJenniferNextRouteTx };
55
+ export { type GcMetricsCallback, type HeapMetricsCallback, registerIitmHooks, registerRitmHooks, startGcMetricsCollection, startHeapMetricsCollection };
package/dist/index.d.ts CHANGED
@@ -52,37 +52,4 @@ type GcMetricsCallback = (gcCount: number, gcTime: number, gcCountDelta: number)
52
52
  */
53
53
  declare function startGcMetricsCollection(intervalMs?: number, callback?: GcMetricsCallback): (() => void) | null;
54
54
 
55
- /**
56
- * Transaction context that is maintained across async operations
57
- */
58
- interface TransactionContext {
59
- id: number;
60
- enable: boolean;
61
- }
62
- /**
63
- * Manages transaction contexts using AsyncLocalStorage
64
- */
65
- declare class TransactionContextManager {
66
- private _asyncLocalStorage;
67
- constructor();
68
- /**
69
- * Create a new transaction context
70
- */
71
- start(): TransactionContext;
72
- /**
73
- * Run a callback within a transaction context scope
74
- * All async operations within this scope will automatically have access to the context
75
- */
76
- run<T>(ctx: TransactionContext, callback: () => T): T;
77
- /**
78
- * Get the current transaction context (if any)
79
- * This works automatically across async boundaries thanks to AsyncLocalStorage
80
- */
81
- getCurrentContext(): TransactionContext | undefined;
82
- }
83
- declare const contextManager: TransactionContextManager;
84
-
85
- type RouteHandler<TRequest extends Request = Request> = (request: TRequest) => Promise<Response> | Response;
86
- declare function withJenniferNextRouteTx<TRequest extends Request>(handler: RouteHandler<TRequest>): RouteHandler<TRequest>;
87
-
88
- export { type GcMetricsCallback, type HeapMetricsCallback, type TransactionContext, TransactionContextManager, contextManager, registerIitmHooks, registerRitmHooks, startGcMetricsCollection, startHeapMetricsCollection, withJenniferNextRouteTx };
55
+ export { type GcMetricsCallback, type HeapMetricsCallback, registerIitmHooks, registerRitmHooks, startGcMetricsCollection, startHeapMetricsCollection };
package/dist/index.js CHANGED
@@ -20,13 +20,10 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/index.ts
21
21
  var index_exports = {};
22
22
  __export(index_exports, {
23
- TransactionContextManager: () => TransactionContextManager,
24
- contextManager: () => contextManager,
25
23
  registerIitmHooks: () => registerIitmHooks,
26
24
  registerRitmHooks: () => registerRitmHooks,
27
25
  startGcMetricsCollection: () => startGcMetricsCollection,
28
- startHeapMetricsCollection: () => startHeapMetricsCollection,
29
- withJenniferNextRouteTx: () => withJenniferNextRouteTx
26
+ startHeapMetricsCollection: () => startHeapMetricsCollection
30
27
  });
31
28
  module.exports = __toCommonJS(index_exports);
32
29
 
@@ -369,8 +366,12 @@ function setNewWmonidCookie(res, txid) {
369
366
  httpOnly: (0, import_jennifer5_agent2.configEnableHttpOnlyForWmonidCookie)()
370
367
  });
371
368
  }
372
- function getWmonidInCookie(req, res, txid) {
369
+ function getWmonid(req, res, txid) {
373
370
  try {
371
+ if ((0, import_jennifer5_agent2.configUsingRemoteAddressForWmonid)()) {
372
+ const clientIp = req.socket?.remoteAddress || "";
373
+ return (0, import_jennifer5_agent2.hashString)(clientIp);
374
+ }
374
375
  const wmonidCookie = getCookie(req, WMONID_COOKIE_NAME);
375
376
  if (wmonidCookie) {
376
377
  return (0, import_jennifer5_agent2.base64ToI64)(wmonidCookie);
@@ -570,7 +571,7 @@ function handleRequestEvent(server, originalEmit, eventName, args) {
570
571
  const [req, res] = args;
571
572
  const ctx = contextManager.start();
572
573
  if (ctx.enable) {
573
- const wmonidInCookie = !(0, import_jennifer5_agent4.configUsingRemoteAddressForWmonid)() ? getWmonidInCookie(req, res, ctx.id) : void 0;
574
+ const wmonid = getWmonid(req, res, ctx.id);
574
575
  const incomingRemotecallInfo = getTopologyInfo(req);
575
576
  setTopologyResponseHeaders(incomingRemotecallInfo, res);
576
577
  (0, import_jennifer5_agent4.createTransactionCtx)({
@@ -579,7 +580,7 @@ function handleRequestEvent(server, originalEmit, eventName, args) {
579
580
  httpHeaders: createHttpHeaders(req),
580
581
  httpUrl: req?.url,
581
582
  clientIp: req?.socket?.remoteAddress,
582
- wmonidInCookie,
583
+ wmonid,
583
584
  incomingRemotecallInfo
584
585
  });
585
586
  return contextManager.run(ctx, () => {
@@ -3487,61 +3488,10 @@ function startGcMetricsCollection(intervalMs = 1e3, callback) {
3487
3488
  };
3488
3489
  return cleanup;
3489
3490
  }
3490
-
3491
- // src/helpers/nextjs/with-jennifer-route-tx.ts
3492
- var import_jennifer5_agent26 = require("@jennifersoft/jennifer5-agent");
3493
- function toHeaderLines(headers) {
3494
- const entries = [];
3495
- headers.forEach((value, key) => {
3496
- entries.push(`${key}:${value}`);
3497
- });
3498
- return entries;
3499
- }
3500
- function resolveHttpUrl(request) {
3501
- if (request.nextUrl) {
3502
- return `${request.nextUrl.pathname}${request.nextUrl.search}`;
3503
- }
3504
- const parsed = new URL(request.url);
3505
- return `${parsed.pathname}${parsed.search}`;
3506
- }
3507
- function withJenniferNextRouteTx(handler) {
3508
- return async function wrappedHandler(request) {
3509
- const ctx = contextManager.start();
3510
- const txId = ctx.id;
3511
- const httpUrl = resolveHttpUrl(request);
3512
- if (!ctx.enable) {
3513
- return handler(request);
3514
- }
3515
- (0, import_jennifer5_agent26.createTransactionCtx)({
3516
- txId,
3517
- method: "next.route",
3518
- httpMethod: request.method,
3519
- httpUrl,
3520
- httpHeaders: toHeaderLines(request.headers)
3521
- });
3522
- return contextManager.run(ctx, async () => {
3523
- try {
3524
- const response = await handler(request);
3525
- (0, import_jennifer5_agent26.releaseTransactionCtx)(txId, {
3526
- httpStatusCode: response.status
3527
- });
3528
- return response;
3529
- } catch (error) {
3530
- (0, import_jennifer5_agent26.releaseTransactionCtx)(txId, {
3531
- httpStatusCode: 500
3532
- });
3533
- throw error;
3534
- }
3535
- });
3536
- };
3537
- }
3538
3491
  // Annotate the CommonJS export names for ESM import in node:
3539
3492
  0 && (module.exports = {
3540
- TransactionContextManager,
3541
- contextManager,
3542
3493
  registerIitmHooks,
3543
3494
  registerRitmHooks,
3544
3495
  startGcMetricsCollection,
3545
- startHeapMetricsCollection,
3546
- withJenniferNextRouteTx
3496
+ startHeapMetricsCollection
3547
3497
  });
package/dist/index.mjs CHANGED
@@ -5,7 +5,6 @@ import { Hook } from "require-in-the-middle";
5
5
  import {
6
6
  info,
7
7
  warn as warn3,
8
- configUsingRemoteAddressForWmonid as configUsingRemoteAddressForWmonid2,
9
8
  createTransactionCtx,
10
9
  releaseTransactionCtx
11
10
  } from "@jennifersoft/jennifer5-agent";
@@ -162,8 +161,10 @@ var contextManager = new TransactionContextManager();
162
161
  import {
163
162
  i64ToBase64,
164
163
  base64ToI64,
164
+ hashString,
165
165
  configEnableHttpOnlyForWmonidCookie,
166
166
  configEnableSecureForWmonidCookie,
167
+ configUsingRemoteAddressForWmonid,
167
168
  warn
168
169
  } from "@jennifersoft/jennifer5-agent";
169
170
 
@@ -349,8 +350,12 @@ function setNewWmonidCookie(res, txid) {
349
350
  httpOnly: configEnableHttpOnlyForWmonidCookie()
350
351
  });
351
352
  }
352
- function getWmonidInCookie(req, res, txid) {
353
+ function getWmonid(req, res, txid) {
353
354
  try {
355
+ if (configUsingRemoteAddressForWmonid()) {
356
+ const clientIp = req.socket?.remoteAddress || "";
357
+ return hashString(clientIp);
358
+ }
354
359
  const wmonidCookie = getCookie(req, WMONID_COOKIE_NAME);
355
360
  if (wmonidCookie) {
356
361
  return base64ToI64(wmonidCookie);
@@ -558,7 +563,7 @@ function handleRequestEvent(server, originalEmit, eventName, args) {
558
563
  const [req, res] = args;
559
564
  const ctx = contextManager.start();
560
565
  if (ctx.enable) {
561
- const wmonidInCookie = !configUsingRemoteAddressForWmonid2() ? getWmonidInCookie(req, res, ctx.id) : void 0;
566
+ const wmonid = getWmonid(req, res, ctx.id);
562
567
  const incomingRemotecallInfo = getTopologyInfo(req);
563
568
  setTopologyResponseHeaders(incomingRemotecallInfo, res);
564
569
  createTransactionCtx({
@@ -567,7 +572,7 @@ function handleRequestEvent(server, originalEmit, eventName, args) {
567
572
  httpHeaders: createHttpHeaders(req),
568
573
  httpUrl: req?.url,
569
574
  clientIp: req?.socket?.remoteAddress,
570
- wmonidInCookie,
575
+ wmonid,
571
576
  incomingRemotecallInfo
572
577
  });
573
578
  return contextManager.run(ctx, () => {
@@ -3577,60 +3582,9 @@ function startGcMetricsCollection(intervalMs = 1e3, callback) {
3577
3582
  };
3578
3583
  return cleanup;
3579
3584
  }
3580
-
3581
- // src/helpers/nextjs/with-jennifer-route-tx.ts
3582
- import { createTransactionCtx as createTransactionCtx3, releaseTransactionCtx as releaseTransactionCtx4 } from "@jennifersoft/jennifer5-agent";
3583
- function toHeaderLines(headers) {
3584
- const entries = [];
3585
- headers.forEach((value, key) => {
3586
- entries.push(`${key}:${value}`);
3587
- });
3588
- return entries;
3589
- }
3590
- function resolveHttpUrl(request) {
3591
- if (request.nextUrl) {
3592
- return `${request.nextUrl.pathname}${request.nextUrl.search}`;
3593
- }
3594
- const parsed = new URL(request.url);
3595
- return `${parsed.pathname}${parsed.search}`;
3596
- }
3597
- function withJenniferNextRouteTx(handler) {
3598
- return async function wrappedHandler(request) {
3599
- const ctx = contextManager.start();
3600
- const txId = ctx.id;
3601
- const httpUrl = resolveHttpUrl(request);
3602
- if (!ctx.enable) {
3603
- return handler(request);
3604
- }
3605
- createTransactionCtx3({
3606
- txId,
3607
- method: "next.route",
3608
- httpMethod: request.method,
3609
- httpUrl,
3610
- httpHeaders: toHeaderLines(request.headers)
3611
- });
3612
- return contextManager.run(ctx, async () => {
3613
- try {
3614
- const response = await handler(request);
3615
- releaseTransactionCtx4(txId, {
3616
- httpStatusCode: response.status
3617
- });
3618
- return response;
3619
- } catch (error) {
3620
- releaseTransactionCtx4(txId, {
3621
- httpStatusCode: 500
3622
- });
3623
- throw error;
3624
- }
3625
- });
3626
- };
3627
- }
3628
3585
  export {
3629
- TransactionContextManager,
3630
- contextManager,
3631
3586
  registerIitmHooks,
3632
3587
  registerRitmHooks,
3633
3588
  startGcMetricsCollection,
3634
- startHeapMetricsCollection,
3635
- withJenniferNextRouteTx
3589
+ startHeapMetricsCollection
3636
3590
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jennifersoft/jennifer5-instrumentation",
3
- "version": "5.6.5-1",
3
+ "version": "5.6.5",
4
4
  "description": "Instrumentation hooks for Jennifer APM",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
@@ -26,8 +26,8 @@
26
26
  "test": "bun test"
27
27
  },
28
28
  "dependencies": {
29
- "@jennifersoft/jennifer5-agent": "5.6.5-1",
30
- "import-in-the-middle": "3.0.1",
29
+ "@jennifersoft/jennifer5-agent": "5.6.5",
30
+ "import-in-the-middle": "3.0.0",
31
31
  "require-in-the-middle": "^8.0.1"
32
32
  },
33
33
  "engines": {