@monocle.sh/adonisjs-agent 1.0.2 → 1.0.3
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.
|
@@ -20,13 +20,30 @@ function getHeader(response, name) {
|
|
|
20
20
|
}
|
|
21
21
|
}
|
|
22
22
|
/**
|
|
23
|
+
* Returns the raw HTTP header string from a ServerResponse.
|
|
24
|
+
* After `writeHead()` is called with inline headers, `getHeader()` returns
|
|
25
|
+
* undefined. Node.js stores the serialized headers in `_header` which is
|
|
26
|
+
* the only reliable way to read them after they've been flushed.
|
|
27
|
+
*/
|
|
28
|
+
function getRawHeader(response) {
|
|
29
|
+
const raw = response._header;
|
|
30
|
+
if (typeof raw === "string") return raw;
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
23
33
|
* Detects the connection type based on response headers.
|
|
24
34
|
* Returns 'sse' for Server-Sent Events, 'websocket' for WebSocket upgrades,
|
|
25
35
|
* or undefined for standard HTTP connections.
|
|
36
|
+
*
|
|
37
|
+
* Checks both `getHeader()` and the raw `_header` string to handle cases
|
|
38
|
+
* where headers are passed inline to `writeHead()` (e.g. @hono/node-server).
|
|
26
39
|
*/
|
|
27
40
|
function detectConnectionType(response) {
|
|
28
41
|
if (getHeader(response, "content-type")?.includes("text/event-stream")) return "sse";
|
|
29
42
|
if (getHeader(response, "upgrade")?.toLowerCase() === "websocket") return "websocket";
|
|
43
|
+
const raw = getRawHeader(response);
|
|
44
|
+
if (!raw) return;
|
|
45
|
+
if (raw.includes("text/event-stream")) return "sse";
|
|
46
|
+
if (raw.toLowerCase().includes("upgrade: websocket")) return "websocket";
|
|
30
47
|
}
|
|
31
48
|
/**
|
|
32
49
|
* Creates a response hook that detects long-running HTTP connections
|
|
@@ -112,23 +112,34 @@ var MailInstrumentation = class extends InstrumentationBase {
|
|
|
112
112
|
}
|
|
113
113
|
/**
|
|
114
114
|
* Patches Mailer.prototype methods with tracing wrappers.
|
|
115
|
+
*
|
|
116
|
+
* Note: InstrumentationBase constructor calls enable() synchronously
|
|
117
|
+
* without awaiting (it ignores the returned Promise). Then instrumentMail()
|
|
118
|
+
* also calls `await enable()`. Setting `this.patched = true` before any
|
|
119
|
+
* `await` prevents the second call from double-patching the prototype,
|
|
120
|
+
* which would create duplicate spans for every email sent.
|
|
115
121
|
*/
|
|
116
122
|
async enable() {
|
|
117
123
|
if (this.patched) return;
|
|
124
|
+
this.patched = true;
|
|
118
125
|
const appRoot = this.getConfig().appRoot;
|
|
119
126
|
const require = createRequire(appRoot ? pathToFileURL(`${appRoot}/package.json`).href : import.meta.url);
|
|
120
127
|
let mailerPath;
|
|
121
128
|
try {
|
|
122
129
|
mailerPath = require.resolve("@adonisjs/mail");
|
|
123
130
|
} catch {
|
|
131
|
+
this.patched = false;
|
|
124
132
|
return;
|
|
125
133
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
try {
|
|
135
|
+
this.mailerClass = (await import(pathToFileURL(mailerPath).href)).Mailer;
|
|
136
|
+
this.originalSendCompiled = this.mailerClass.prototype.sendCompiled;
|
|
137
|
+
this.originalSendLaterCompiled = this.mailerClass.prototype.sendLaterCompiled;
|
|
138
|
+
this.mailerClass.prototype.sendCompiled = this.#createSendCompiledWrapper(this.originalSendCompiled);
|
|
139
|
+
this.mailerClass.prototype.sendLaterCompiled = this.#createSendLaterCompiledWrapper(this.originalSendLaterCompiled);
|
|
140
|
+
} catch {
|
|
141
|
+
this.patched = false;
|
|
142
|
+
}
|
|
132
143
|
}
|
|
133
144
|
/**
|
|
134
145
|
* Restores original Mailer.prototype methods.
|
|
@@ -11,21 +11,31 @@ import { pathToFileURL } from "node:url";
|
|
|
11
11
|
async function instrumentQueue(config, appRoot) {
|
|
12
12
|
if (config.enabled === false) return void 0;
|
|
13
13
|
const appRequire = createRequire(appRoot ? pathToFileURL(`${appRoot}/package.json`).href : import.meta.url);
|
|
14
|
+
let queueOtelPath;
|
|
14
15
|
try {
|
|
15
|
-
appRequire.resolve("@boringnode/queue");
|
|
16
|
+
queueOtelPath = appRequire.resolve("@boringnode/queue/otel");
|
|
16
17
|
} catch {
|
|
17
|
-
|
|
18
|
+
try {
|
|
19
|
+
queueOtelPath = appRequire.resolve("@adonisjs/queue/otel");
|
|
20
|
+
} catch {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
18
23
|
}
|
|
19
|
-
const { QueueInstrumentation } = await import(
|
|
24
|
+
const { QueueInstrumentation } = await import(pathToFileURL(queueOtelPath).href);
|
|
20
25
|
const instrumentation = new QueueInstrumentation({
|
|
21
26
|
executionSpanLinkMode: config.executionSpanLinkMode,
|
|
22
27
|
messagingSystem: config.messagingSystem
|
|
23
28
|
});
|
|
24
29
|
instrumentation.enable();
|
|
25
30
|
try {
|
|
26
|
-
const queueModule = await import("@boringnode/queue");
|
|
31
|
+
const queueModule = await import(pathToFileURL(appRequire.resolve("@boringnode/queue")).href);
|
|
27
32
|
instrumentation.manuallyRegister(queueModule);
|
|
28
|
-
} catch {
|
|
33
|
+
} catch {
|
|
34
|
+
try {
|
|
35
|
+
const queueModule = await import(pathToFileURL(appRequire.resolve("@adonisjs/queue")).href);
|
|
36
|
+
instrumentation.manuallyRegister(queueModule);
|
|
37
|
+
} catch {}
|
|
38
|
+
}
|
|
29
39
|
return instrumentation;
|
|
30
40
|
}
|
|
31
41
|
//#endregion
|