@sentienguard/apm 1.0.16 → 1.0.17
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/package.json +1 -1
- package/src/tracing.js +25 -0
package/package.json
CHANGED
package/src/tracing.js
CHANGED
|
@@ -141,6 +141,31 @@ export function startTracing() {
|
|
|
141
141
|
setAttrNumber(span, 'http.status_code', response.statusCode);
|
|
142
142
|
}
|
|
143
143
|
}
|
|
144
|
+
,
|
|
145
|
+
/**
|
|
146
|
+
* More reliable cross-version hook that runs with both request+response context.
|
|
147
|
+
* Used as a safety net to guarantee basic attributes exist on spans.
|
|
148
|
+
*/
|
|
149
|
+
applyCustomAttributesOnSpan: (span, request, response) => {
|
|
150
|
+
// Incoming request (SERVER)
|
|
151
|
+
if (request && typeof request === 'object' && 'headers' in request && 'method' in request) {
|
|
152
|
+
setAttr(span, 'http.method', request.method);
|
|
153
|
+
setAttr(span, 'http.target', request.url);
|
|
154
|
+
setAttr(span, 'http.host', safeHostFromIncoming(request));
|
|
155
|
+
} else {
|
|
156
|
+
// Outgoing request (CLIENT)
|
|
157
|
+
setAttr(span, 'http.method', request?.method);
|
|
158
|
+
const url = safeUrlFromOutgoingRequest(request);
|
|
159
|
+
if (url) setAttr(span, 'http.url', url);
|
|
160
|
+
const host = request?.hostname || (request?.host ? String(request.host).split(':')[0] : '');
|
|
161
|
+
if (host) setAttr(span, 'net.peer.name', host);
|
|
162
|
+
if (request?.port) setAttrNumber(span, 'net.peer.port', request.port);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (response && typeof response === 'object' && 'statusCode' in response) {
|
|
166
|
+
setAttrNumber(span, 'http.status_code', response.statusCode);
|
|
167
|
+
}
|
|
168
|
+
}
|
|
144
169
|
});
|
|
145
170
|
|
|
146
171
|
const expressInstrumentation = new ExpressInstrumentation();
|