braintrust 3.4.0 → 3.6.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 (58) hide show
  1. package/dev/dist/index.d.mts +49 -7
  2. package/dev/dist/index.d.ts +49 -7
  3. package/dev/dist/index.js +2383 -494
  4. package/dev/dist/index.mjs +2213 -324
  5. package/dist/auto-instrumentations/bundler/esbuild.cjs +289 -10
  6. package/dist/auto-instrumentations/bundler/esbuild.d.mts +2 -2
  7. package/dist/auto-instrumentations/bundler/esbuild.d.ts +2 -2
  8. package/dist/auto-instrumentations/bundler/esbuild.mjs +2 -2
  9. package/dist/auto-instrumentations/bundler/rollup.cjs +289 -10
  10. package/dist/auto-instrumentations/bundler/rollup.mjs +2 -2
  11. package/dist/auto-instrumentations/bundler/vite.cjs +289 -10
  12. package/dist/auto-instrumentations/bundler/vite.d.mts +2 -2
  13. package/dist/auto-instrumentations/bundler/vite.d.ts +2 -2
  14. package/dist/auto-instrumentations/bundler/vite.mjs +2 -2
  15. package/dist/auto-instrumentations/bundler/webpack.cjs +289 -10
  16. package/dist/auto-instrumentations/bundler/webpack.d.mts +2 -2
  17. package/dist/auto-instrumentations/bundler/webpack.d.ts +2 -2
  18. package/dist/auto-instrumentations/bundler/webpack.mjs +2 -2
  19. package/dist/auto-instrumentations/chunk-EVUKFMHG.mjs +41 -0
  20. package/dist/auto-instrumentations/{chunk-LVWWLUMN.mjs → chunk-F7WAXFNM.mjs} +290 -11
  21. package/dist/auto-instrumentations/chunk-VLEJ5AEK.mjs +41 -0
  22. package/dist/auto-instrumentations/{chunk-D5ZPIUEL.mjs → chunk-WOUC73KB.mjs} +3 -1
  23. package/dist/auto-instrumentations/hook.mjs +358 -48
  24. package/dist/auto-instrumentations/index.cjs +290 -10
  25. package/dist/auto-instrumentations/index.d.mts +3 -1
  26. package/dist/auto-instrumentations/index.d.ts +3 -1
  27. package/dist/auto-instrumentations/index.mjs +3 -1
  28. package/dist/auto-instrumentations/loader/cjs-patch.cjs +32 -10
  29. package/dist/auto-instrumentations/loader/cjs-patch.mjs +10 -5
  30. package/dist/auto-instrumentations/loader/esm-hook.mjs +4 -4
  31. package/dist/auto-instrumentations/loader/get-package-version.cjs +28 -8
  32. package/dist/auto-instrumentations/loader/get-package-version.d.mts +2 -1
  33. package/dist/auto-instrumentations/loader/get-package-version.d.ts +2 -1
  34. package/dist/auto-instrumentations/loader/get-package-version.mjs +3 -1
  35. package/dist/browser.d.mts +357 -271
  36. package/dist/browser.d.ts +357 -271
  37. package/dist/browser.js +2345 -343
  38. package/dist/browser.mjs +2345 -343
  39. package/dist/cli.js +2296 -414
  40. package/dist/edge-light.d.mts +1 -1
  41. package/dist/edge-light.d.ts +1 -1
  42. package/dist/edge-light.js +2292 -315
  43. package/dist/edge-light.mjs +2292 -315
  44. package/dist/index.d.mts +370 -284
  45. package/dist/index.d.ts +370 -284
  46. package/dist/index.js +2642 -638
  47. package/dist/index.mjs +2385 -381
  48. package/dist/instrumentation/index.d.mts +3 -0
  49. package/dist/instrumentation/index.d.ts +3 -0
  50. package/dist/instrumentation/index.js +1955 -198
  51. package/dist/instrumentation/index.mjs +1955 -198
  52. package/dist/workerd.d.mts +1 -1
  53. package/dist/workerd.d.ts +1 -1
  54. package/dist/workerd.js +2292 -315
  55. package/dist/workerd.mjs +2292 -315
  56. package/package.json +22 -6
  57. package/dist/auto-instrumentations/chunk-XDBPUTVE.mjs +0 -22
  58. package/dist/auto-instrumentations/chunk-ZEC7BCL4.mjs +0 -22
@@ -24,6 +24,7 @@ __export(index_exports, {
24
24
  anthropicConfigs: () => anthropicConfigs,
25
25
  claudeAgentSDKConfigs: () => claudeAgentSDKConfigs,
26
26
  googleGenAIConfigs: () => googleGenAIConfigs,
27
+ openRouterConfigs: () => openRouterConfigs,
27
28
  openaiConfigs: () => openaiConfigs
28
29
  });
29
30
  module.exports = __toCommonJS(index_exports);
@@ -41,8 +42,54 @@ var DefaultAsyncLocalStorage = class {
41
42
  return void 0;
42
43
  }
43
44
  };
44
- var DefaultTracingChannel = class {
45
+ var DefaultChannel = class {
46
+ constructor(name) {
47
+ this.name = name;
48
+ }
45
49
  hasSubscribers = false;
50
+ subscribe(_subscription) {
51
+ }
52
+ unsubscribe(_subscription) {
53
+ return false;
54
+ }
55
+ bindStore(_store, _transform) {
56
+ }
57
+ unbindStore(_store) {
58
+ return false;
59
+ }
60
+ publish(_message) {
61
+ }
62
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
63
+ runStores(_message, fn, thisArg, ...args) {
64
+ return fn.apply(thisArg, args);
65
+ }
66
+ };
67
+ var DefaultTracingChannel = class {
68
+ start;
69
+ end;
70
+ asyncStart;
71
+ asyncEnd;
72
+ error;
73
+ constructor(nameOrChannels) {
74
+ if (typeof nameOrChannels === "string") {
75
+ this.start = new DefaultChannel(`tracing:${nameOrChannels}:start`);
76
+ this.end = new DefaultChannel(`tracing:${nameOrChannels}:end`);
77
+ this.asyncStart = new DefaultChannel(
78
+ `tracing:${nameOrChannels}:asyncStart`
79
+ );
80
+ this.asyncEnd = new DefaultChannel(`tracing:${nameOrChannels}:asyncEnd`);
81
+ this.error = new DefaultChannel(`tracing:${nameOrChannels}:error`);
82
+ return;
83
+ }
84
+ this.start = nameOrChannels.start ?? new DefaultChannel("tracing:start");
85
+ this.end = nameOrChannels.end ?? new DefaultChannel("tracing:end");
86
+ this.asyncStart = nameOrChannels.asyncStart ?? new DefaultChannel("tracing:asyncStart");
87
+ this.asyncEnd = nameOrChannels.asyncEnd ?? new DefaultChannel("tracing:asyncEnd");
88
+ this.error = nameOrChannels.error ?? new DefaultChannel("tracing:error");
89
+ }
90
+ get hasSubscribers() {
91
+ return this.start.hasSubscribers || this.end.hasSubscribers || this.asyncStart.hasSubscribers || this.asyncEnd.hasSubscribers || this.error.hasSubscribers;
92
+ }
46
93
  subscribe(_handlers) {
47
94
  }
48
95
  unsubscribe(_handlers) {
@@ -70,7 +117,7 @@ var iso = {
70
117
  getCallerLocation: () => void 0,
71
118
  newAsyncLocalStorage: () => new DefaultAsyncLocalStorage(),
72
119
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
73
- newTracingChannel: (_nameOrChannels) => new DefaultTracingChannel(),
120
+ newTracingChannel: (nameOrChannels) => new DefaultTracingChannel(nameOrChannels),
74
121
  processOn: (_0, _1) => {
75
122
  },
76
123
  basename: (filepath) => filepath.split(/[\\/]/).pop() || filepath,
@@ -380,6 +427,10 @@ var aiSDKChannels = defineChannels("ai", {
380
427
  channelName: "streamText",
381
428
  kind: "async"
382
429
  }),
430
+ streamTextSync: channel({
431
+ channelName: "streamText.sync",
432
+ kind: "sync-stream"
433
+ }),
383
434
  generateObject: channel({
384
435
  channelName: "generateObject",
385
436
  kind: "async"
@@ -388,6 +439,10 @@ var aiSDKChannels = defineChannels("ai", {
388
439
  channelName: "streamObject",
389
440
  kind: "async"
390
441
  }),
442
+ streamObjectSync: channel({
443
+ channelName: "streamObject.sync",
444
+ kind: "sync-stream"
445
+ }),
391
446
  agentGenerate: channel({
392
447
  channelName: "Agent.generate",
393
448
  kind: "async"
@@ -395,6 +450,14 @@ var aiSDKChannels = defineChannels("ai", {
395
450
  agentStream: channel({
396
451
  channelName: "Agent.stream",
397
452
  kind: "async"
453
+ }),
454
+ toolLoopAgentGenerate: channel({
455
+ channelName: "ToolLoopAgent.generate",
456
+ kind: "async"
457
+ }),
458
+ toolLoopAgentStream: channel({
459
+ channelName: "ToolLoopAgent.stream",
460
+ kind: "async"
398
461
  })
399
462
  });
400
463
 
@@ -413,6 +476,18 @@ var aiSDKConfigs = [
413
476
  kind: "Async"
414
477
  }
415
478
  },
479
+ {
480
+ channelName: aiSDKChannels.generateText.channelName,
481
+ module: {
482
+ name: "ai",
483
+ versionRange: ">=3.0.0",
484
+ filePath: "dist/index.js"
485
+ },
486
+ functionQuery: {
487
+ functionName: "generateText",
488
+ kind: "Async"
489
+ }
490
+ },
416
491
  // streamText - async function
417
492
  {
418
493
  channelName: aiSDKChannels.streamText.channelName,
@@ -426,6 +501,18 @@ var aiSDKConfigs = [
426
501
  kind: "Async"
427
502
  }
428
503
  },
504
+ {
505
+ channelName: aiSDKChannels.streamTextSync.channelName,
506
+ module: {
507
+ name: "ai",
508
+ versionRange: ">=3.0.0",
509
+ filePath: "dist/index.js"
510
+ },
511
+ functionQuery: {
512
+ functionName: "streamText",
513
+ kind: "Sync"
514
+ }
515
+ },
429
516
  // generateObject - async function
430
517
  {
431
518
  channelName: aiSDKChannels.generateObject.channelName,
@@ -439,6 +526,18 @@ var aiSDKConfigs = [
439
526
  kind: "Async"
440
527
  }
441
528
  },
529
+ {
530
+ channelName: aiSDKChannels.generateObject.channelName,
531
+ module: {
532
+ name: "ai",
533
+ versionRange: ">=3.0.0",
534
+ filePath: "dist/index.js"
535
+ },
536
+ functionQuery: {
537
+ functionName: "generateObject",
538
+ kind: "Async"
539
+ }
540
+ },
442
541
  // streamObject - async function
443
542
  {
444
543
  channelName: aiSDKChannels.streamObject.channelName,
@@ -452,32 +551,132 @@ var aiSDKConfigs = [
452
551
  kind: "Async"
453
552
  }
454
553
  },
455
- // Agent.generate - async method (v3-v5 only, Agent structure changed in v6)
554
+ {
555
+ channelName: aiSDKChannels.streamObjectSync.channelName,
556
+ module: {
557
+ name: "ai",
558
+ versionRange: ">=3.0.0",
559
+ filePath: "dist/index.js"
560
+ },
561
+ functionQuery: {
562
+ functionName: "streamObject",
563
+ kind: "Sync"
564
+ }
565
+ },
566
+ // Agent.generate - async method (v5 only)
567
+ // The compiled AI SDK bundle emits this as an anonymous class method, so we
568
+ // target the first async `generate` method in the file instead of a class name.
456
569
  {
457
570
  channelName: aiSDKChannels.agentGenerate.channelName,
458
571
  module: {
459
572
  name: "ai",
460
- versionRange: ">=3.0.0 <6.0.0",
573
+ versionRange: ">=5.0.0 <6.0.0",
461
574
  filePath: "dist/index.mjs"
462
575
  },
463
576
  functionQuery: {
464
- className: "Agent",
465
577
  methodName: "generate",
466
- kind: "Async"
578
+ kind: "Async",
579
+ index: 0
467
580
  }
468
581
  },
469
- // Agent.stream - async method (v3-v5 only, Agent structure changed in v6)
582
+ {
583
+ channelName: aiSDKChannels.agentGenerate.channelName,
584
+ module: {
585
+ name: "ai",
586
+ versionRange: ">=5.0.0 <6.0.0",
587
+ filePath: "dist/index.js"
588
+ },
589
+ functionQuery: {
590
+ methodName: "generate",
591
+ kind: "Async",
592
+ index: 0
593
+ }
594
+ },
595
+ // Agent.stream - async method (v5 only)
596
+ // The compiled AI SDK bundle emits this as an anonymous class method, so we
597
+ // target the first async `stream` method in the file instead of a class name.
470
598
  {
471
599
  channelName: aiSDKChannels.agentStream.channelName,
472
600
  module: {
473
601
  name: "ai",
474
- versionRange: ">=3.0.0 <6.0.0",
602
+ versionRange: ">=5.0.0 <6.0.0",
475
603
  filePath: "dist/index.mjs"
476
604
  },
477
605
  functionQuery: {
478
- className: "Agent",
479
606
  methodName: "stream",
480
- kind: "Async"
607
+ kind: "Async",
608
+ index: 0
609
+ }
610
+ },
611
+ {
612
+ channelName: aiSDKChannels.agentStream.channelName,
613
+ module: {
614
+ name: "ai",
615
+ versionRange: ">=5.0.0 <6.0.0",
616
+ filePath: "dist/index.js"
617
+ },
618
+ functionQuery: {
619
+ methodName: "stream",
620
+ kind: "Async",
621
+ index: 0
622
+ }
623
+ },
624
+ // ToolLoopAgent.generate - async method (v6 only, Experimental_Agent is an alias)
625
+ // The compiled AI SDK bundle emits this as an anonymous class method, so we
626
+ // target the first async `generate` method in the file instead of a class name.
627
+ {
628
+ channelName: aiSDKChannels.toolLoopAgentGenerate.channelName,
629
+ module: {
630
+ name: "ai",
631
+ versionRange: ">=6.0.0 <7.0.0",
632
+ filePath: "dist/index.mjs"
633
+ },
634
+ functionQuery: {
635
+ methodName: "generate",
636
+ kind: "Async",
637
+ index: 0
638
+ }
639
+ },
640
+ {
641
+ channelName: aiSDKChannels.toolLoopAgentGenerate.channelName,
642
+ module: {
643
+ name: "ai",
644
+ versionRange: ">=6.0.0 <7.0.0",
645
+ filePath: "dist/index.js"
646
+ },
647
+ functionQuery: {
648
+ methodName: "generate",
649
+ kind: "Async",
650
+ index: 0
651
+ }
652
+ },
653
+ // ToolLoopAgent.stream - async method (v6 only, Experimental_Agent is an alias)
654
+ // The compiled AI SDK bundle emits this as an anonymous class method, so we
655
+ // target the first async `stream` method in the file instead of a class name.
656
+ {
657
+ channelName: aiSDKChannels.toolLoopAgentStream.channelName,
658
+ module: {
659
+ name: "ai",
660
+ versionRange: ">=6.0.0 <7.0.0",
661
+ filePath: "dist/index.mjs"
662
+ },
663
+ functionQuery: {
664
+ methodName: "stream",
665
+ kind: "Async",
666
+ index: 0
667
+ }
668
+ },
669
+ {
670
+ channelName: aiSDKChannels.toolLoopAgentStream.channelName,
671
+ module: {
672
+ name: "ai",
673
+ versionRange: ">=6.0.0 <7.0.0",
674
+ filePath: "dist/index.js"
675
+ },
676
+ functionQuery: {
677
+ methodName: "stream",
678
+ kind: "Async",
679
+ index: 0
481
680
  }
482
681
  }
483
682
  ];
@@ -555,11 +754,92 @@ var googleGenAIConfigs = [
555
754
  }
556
755
  }
557
756
  ];
757
+
758
+ // src/instrumentation/plugins/openrouter-channels.ts
759
+ var openRouterChannels = defineChannels("@openrouter/sdk", {
760
+ chatSend: channel({
761
+ channelName: "chat.send",
762
+ kind: "async"
763
+ }),
764
+ embeddingsGenerate: channel({
765
+ channelName: "embeddings.generate",
766
+ kind: "async"
767
+ }),
768
+ betaResponsesSend: channel({
769
+ channelName: "beta.responses.send",
770
+ kind: "async"
771
+ }),
772
+ callModel: channel({
773
+ channelName: "callModel",
774
+ kind: "sync-stream"
775
+ }),
776
+ toolExecute: channel({
777
+ channelName: "tool.execute",
778
+ kind: "async"
779
+ })
780
+ });
781
+
782
+ // src/auto-instrumentations/configs/openrouter.ts
783
+ var openRouterConfigs = [
784
+ {
785
+ channelName: openRouterChannels.chatSend.channelName,
786
+ module: {
787
+ name: "@openrouter/sdk",
788
+ versionRange: ">=0.9.11 <1.0.0",
789
+ filePath: "esm/sdk/chat.js"
790
+ },
791
+ functionQuery: {
792
+ className: "Chat",
793
+ methodName: "send",
794
+ kind: "Async"
795
+ }
796
+ },
797
+ {
798
+ channelName: openRouterChannels.embeddingsGenerate.channelName,
799
+ module: {
800
+ name: "@openrouter/sdk",
801
+ versionRange: ">=0.9.11 <1.0.0",
802
+ filePath: "esm/sdk/embeddings.js"
803
+ },
804
+ functionQuery: {
805
+ className: "Embeddings",
806
+ methodName: "generate",
807
+ kind: "Async"
808
+ }
809
+ },
810
+ {
811
+ channelName: openRouterChannels.betaResponsesSend.channelName,
812
+ module: {
813
+ name: "@openrouter/sdk",
814
+ versionRange: ">=0.9.11 <1.0.0",
815
+ filePath: "esm/sdk/responses.js"
816
+ },
817
+ functionQuery: {
818
+ className: "Responses",
819
+ methodName: "send",
820
+ kind: "Async"
821
+ }
822
+ },
823
+ {
824
+ channelName: openRouterChannels.callModel.channelName,
825
+ module: {
826
+ name: "@openrouter/sdk",
827
+ versionRange: ">=0.9.11 <1.0.0",
828
+ filePath: "esm/sdk/sdk.js"
829
+ },
830
+ functionQuery: {
831
+ className: "OpenRouter",
832
+ methodName: "callModel",
833
+ kind: "Sync"
834
+ }
835
+ }
836
+ ];
558
837
  // Annotate the CommonJS export names for ESM import in node:
559
838
  0 && (module.exports = {
560
839
  aiSDKConfigs,
561
840
  anthropicConfigs,
562
841
  claudeAgentSDKConfigs,
563
842
  googleGenAIConfigs,
843
+ openRouterConfigs,
564
844
  openaiConfigs
565
845
  });
@@ -66,4 +66,6 @@ declare const claudeAgentSDKConfigs: InstrumentationConfig[];
66
66
  */
67
67
  declare const googleGenAIConfigs: InstrumentationConfig[];
68
68
 
69
- export { aiSDKConfigs, anthropicConfigs, claudeAgentSDKConfigs, googleGenAIConfigs, openaiConfigs };
69
+ declare const openRouterConfigs: InstrumentationConfig[];
70
+
71
+ export { aiSDKConfigs, anthropicConfigs, claudeAgentSDKConfigs, googleGenAIConfigs, openRouterConfigs, openaiConfigs };
@@ -66,4 +66,6 @@ declare const claudeAgentSDKConfigs: InstrumentationConfig[];
66
66
  */
67
67
  declare const googleGenAIConfigs: InstrumentationConfig[];
68
68
 
69
- export { aiSDKConfigs, anthropicConfigs, claudeAgentSDKConfigs, googleGenAIConfigs, openaiConfigs };
69
+ declare const openRouterConfigs: InstrumentationConfig[];
70
+
71
+ export { aiSDKConfigs, anthropicConfigs, claudeAgentSDKConfigs, googleGenAIConfigs, openRouterConfigs, openaiConfigs };
@@ -3,12 +3,14 @@ import {
3
3
  anthropicConfigs,
4
4
  claudeAgentSDKConfigs,
5
5
  googleGenAIConfigs,
6
+ openRouterConfigs,
6
7
  openaiConfigs
7
- } from "./chunk-LVWWLUMN.mjs";
8
+ } from "./chunk-F7WAXFNM.mjs";
8
9
  export {
9
10
  aiSDKConfigs,
10
11
  anthropicConfigs,
11
12
  claudeAgentSDKConfigs,
12
13
  googleGenAIConfigs,
14
+ openRouterConfigs,
13
15
  openaiConfigs
14
16
  };
@@ -42,19 +42,37 @@ var import_module_details_from_path = __toESM(require("module-details-from-path"
42
42
  var import_node_fs = require("fs");
43
43
  var import_node_path = require("path");
44
44
  var packageVersions = /* @__PURE__ */ new Map();
45
- function getPackageVersion(baseDir) {
46
- if (packageVersions.has(baseDir)) {
47
- return packageVersions.get(baseDir);
48
- }
45
+ var packageNames = /* @__PURE__ */ new Map();
46
+ function readPackageJson(baseDir) {
49
47
  try {
50
48
  const packageJsonPath = (0, import_node_path.join)(baseDir, "package.json");
51
49
  const jsonFile = (0, import_node_fs.readFileSync)(packageJsonPath, "utf8");
52
- const { version } = JSON.parse(jsonFile);
53
- packageVersions.set(baseDir, version);
54
- return version;
50
+ return JSON.parse(jsonFile);
55
51
  } catch {
56
- return process.version.slice(1);
52
+ return void 0;
53
+ }
54
+ }
55
+ function getPackageVersion(baseDir) {
56
+ if (packageVersions.has(baseDir)) {
57
+ return packageVersions.get(baseDir);
57
58
  }
59
+ const packageJson = readPackageJson(baseDir);
60
+ if (typeof packageJson?.version === "string") {
61
+ packageVersions.set(baseDir, packageJson.version);
62
+ return packageJson.version;
63
+ }
64
+ return process.version.slice(1);
65
+ }
66
+ function getPackageName(baseDir) {
67
+ if (packageNames.has(baseDir)) {
68
+ return packageNames.get(baseDir);
69
+ }
70
+ const packageJson = readPackageJson(baseDir);
71
+ if (typeof packageJson?.name === "string") {
72
+ packageNames.set(baseDir, packageJson.name);
73
+ return packageJson.name;
74
+ }
75
+ return void 0;
58
76
  }
59
77
 
60
78
  // src/auto-instrumentations/loader/cjs-patch.ts
@@ -80,11 +98,15 @@ var ModulePatch = class {
80
98
  const [content, filename] = args;
81
99
  const normalizedForPlatform = filename.split("/").join(import_node_path2.sep);
82
100
  const resolvedModule = (0, import_module_details_from_path.default)(normalizedForPlatform);
83
- if (resolvedModule && self.packages.has(resolvedModule.name)) {
101
+ if (resolvedModule) {
102
+ const packageName = getPackageName(resolvedModule.basedir) ?? resolvedModule.name;
103
+ if (!self.packages.has(packageName)) {
104
+ return self.originalCompile.apply(this, args);
105
+ }
84
106
  const version = getPackageVersion(resolvedModule.basedir);
85
107
  const normalizedModulePath = resolvedModule.path.replace(/\\/g, "/");
86
108
  const transformer = self.instrumentator.getTransformer(
87
- resolvedModule.name,
109
+ packageName,
88
110
  version,
89
111
  normalizedModulePath
90
112
  );
@@ -1,13 +1,14 @@
1
1
  import {
2
+ getPackageName,
2
3
  getPackageVersion
3
- } from "../chunk-XDBPUTVE.mjs";
4
+ } from "../chunk-VLEJ5AEK.mjs";
4
5
 
5
6
  // src/auto-instrumentations/loader/cjs-patch.ts
6
7
  import {
7
8
  create
8
9
  } from "@apm-js-collab/code-transformer";
9
- import * as Module from "node:module";
10
- import { sep } from "node:path";
10
+ import * as Module from "module";
11
+ import { sep } from "path";
11
12
  import moduleDetailsFromPath from "module-details-from-path";
12
13
  var ModulePatch = class {
13
14
  packages;
@@ -31,11 +32,15 @@ var ModulePatch = class {
31
32
  const [content, filename] = args;
32
33
  const normalizedForPlatform = filename.split("/").join(sep);
33
34
  const resolvedModule = moduleDetailsFromPath(normalizedForPlatform);
34
- if (resolvedModule && self.packages.has(resolvedModule.name)) {
35
+ if (resolvedModule) {
36
+ const packageName = getPackageName(resolvedModule.basedir) ?? resolvedModule.name;
37
+ if (!self.packages.has(packageName)) {
38
+ return self.originalCompile.apply(this, args);
39
+ }
35
40
  const version = getPackageVersion(resolvedModule.basedir);
36
41
  const normalizedModulePath = resolvedModule.path.replace(/\\/g, "/");
37
42
  const transformer = self.instrumentator.getTransformer(
38
- resolvedModule.name,
43
+ packageName,
39
44
  version,
40
45
  normalizedModulePath
41
46
  );
@@ -1,11 +1,11 @@
1
1
  import {
2
2
  getPackageVersion
3
- } from "../chunk-ZEC7BCL4.mjs";
3
+ } from "../chunk-EVUKFMHG.mjs";
4
4
 
5
5
  // src/auto-instrumentations/loader/esm-hook.mts
6
- import { readFile } from "node:fs/promises";
7
- import { fileURLToPath } from "node:url";
8
- import { sep } from "node:path";
6
+ import { readFile } from "fs/promises";
7
+ import { fileURLToPath } from "url";
8
+ import { sep } from "path";
9
9
  import {
10
10
  create
11
11
  } from "@apm-js-collab/code-transformer";
@@ -20,27 +20,47 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/auto-instrumentations/loader/get-package-version.ts
21
21
  var get_package_version_exports = {};
22
22
  __export(get_package_version_exports, {
23
+ getPackageName: () => getPackageName,
23
24
  getPackageVersion: () => getPackageVersion
24
25
  });
25
26
  module.exports = __toCommonJS(get_package_version_exports);
26
27
  var import_node_fs = require("fs");
27
28
  var import_node_path = require("path");
28
29
  var packageVersions = /* @__PURE__ */ new Map();
29
- function getPackageVersion(baseDir) {
30
- if (packageVersions.has(baseDir)) {
31
- return packageVersions.get(baseDir);
32
- }
30
+ var packageNames = /* @__PURE__ */ new Map();
31
+ function readPackageJson(baseDir) {
33
32
  try {
34
33
  const packageJsonPath = (0, import_node_path.join)(baseDir, "package.json");
35
34
  const jsonFile = (0, import_node_fs.readFileSync)(packageJsonPath, "utf8");
36
- const { version } = JSON.parse(jsonFile);
37
- packageVersions.set(baseDir, version);
38
- return version;
35
+ return JSON.parse(jsonFile);
39
36
  } catch {
40
- return process.version.slice(1);
37
+ return void 0;
38
+ }
39
+ }
40
+ function getPackageVersion(baseDir) {
41
+ if (packageVersions.has(baseDir)) {
42
+ return packageVersions.get(baseDir);
43
+ }
44
+ const packageJson = readPackageJson(baseDir);
45
+ if (typeof packageJson?.version === "string") {
46
+ packageVersions.set(baseDir, packageJson.version);
47
+ return packageJson.version;
48
+ }
49
+ return process.version.slice(1);
50
+ }
51
+ function getPackageName(baseDir) {
52
+ if (packageNames.has(baseDir)) {
53
+ return packageNames.get(baseDir);
54
+ }
55
+ const packageJson = readPackageJson(baseDir);
56
+ if (typeof packageJson?.name === "string") {
57
+ packageNames.set(baseDir, packageJson.name);
58
+ return packageJson.name;
41
59
  }
60
+ return void 0;
42
61
  }
43
62
  // Annotate the CommonJS export names for ESM import in node:
44
63
  0 && (module.exports = {
64
+ getPackageName,
45
65
  getPackageVersion
46
66
  });
@@ -3,5 +3,6 @@
3
3
  * If the package.json file cannot be read, it defaults to the Node.js version.
4
4
  */
5
5
  declare function getPackageVersion(baseDir: string): string;
6
+ declare function getPackageName(baseDir: string): string | undefined;
6
7
 
7
- export { getPackageVersion };
8
+ export { getPackageName, getPackageVersion };
@@ -3,5 +3,6 @@
3
3
  * If the package.json file cannot be read, it defaults to the Node.js version.
4
4
  */
5
5
  declare function getPackageVersion(baseDir: string): string;
6
+ declare function getPackageName(baseDir: string): string | undefined;
6
7
 
7
- export { getPackageVersion };
8
+ export { getPackageName, getPackageVersion };
@@ -1,6 +1,8 @@
1
1
  import {
2
+ getPackageName,
2
3
  getPackageVersion
3
- } from "../chunk-XDBPUTVE.mjs";
4
+ } from "../chunk-VLEJ5AEK.mjs";
4
5
  export {
6
+ getPackageName,
5
7
  getPackageVersion
6
8
  };