@teamkeel/functions-runtime 0.348.0 → 0.350.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 (2) hide show
  1. package/package.json +1 -1
  2. package/src/tracing.js +50 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamkeel/functions-runtime",
3
- "version": "0.348.0",
3
+ "version": "0.350.0",
4
4
  "description": "Internal package used by @teamkeel/sdk",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/tracing.js CHANGED
@@ -54,6 +54,55 @@ function patchFetch() {
54
54
  }
55
55
  }
56
56
 
57
+ function patchConsoleLog() {
58
+ if (!console.log.patched) {
59
+ const originalConsoleLog = console.log;
60
+
61
+ console.log = (...args) => {
62
+ const span = opentelemetry.trace.getActiveSpan();
63
+ if (span) {
64
+ const output = args
65
+ .map((arg) => {
66
+ if (arg instanceof Error) {
67
+ return arg.stack;
68
+ }
69
+ if (typeof arg === "object") {
70
+ try {
71
+ return JSON.stringify(arg, getCircularReplacer());
72
+ } catch (error) {
73
+ return "[Object with circular references]";
74
+ }
75
+ }
76
+ if (typeof arg === "function") {
77
+ return arg() || arg.name || arg.toString();
78
+ }
79
+ return String(arg);
80
+ })
81
+ .join(" ");
82
+
83
+ span.addEvent(output);
84
+ }
85
+ originalConsoleLog(...args);
86
+ };
87
+
88
+ console.log.patched = true;
89
+ }
90
+ }
91
+
92
+ // Utility to handle circular references in objects
93
+ function getCircularReplacer() {
94
+ const seen = new WeakSet();
95
+ return (key, value) => {
96
+ if (typeof value === "object" && value !== null) {
97
+ if (seen.has(value)) {
98
+ return "[Circular]";
99
+ }
100
+ seen.add(value);
101
+ }
102
+ return value;
103
+ };
104
+ }
105
+
57
106
  function init() {
58
107
  if (process.env.KEEL_TRACING_ENABLED == "true") {
59
108
  const provider = new NodeTracerProvider({
@@ -67,6 +116,7 @@ function init() {
67
116
  }
68
117
 
69
118
  patchFetch();
119
+ patchConsoleLog();
70
120
  }
71
121
 
72
122
  function getTracer() {