@carecard/telemetry 3.19.0 → 3.20.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@carecard/telemetry",
3
- "version": "3.19.0",
3
+ "version": "3.20.0",
4
4
  "description": "Privacy-safe OpenTelemetry tracing for CareCard Node.js services",
5
5
  "main": "index.js",
6
6
  "module": "index.mjs",
@@ -32,11 +32,24 @@ function isRoutineRequest(request) {
32
32
  );
33
33
  }
34
34
 
35
+ // Pattern: Normalizer - produces the bracketed URL host form for DNS, IPv4, and IPv6 inputs.
36
+ function normalizeRequestHost(requestHost) {
37
+ const host = String(requestHost || '')
38
+ .replace(/^https?:\/\//, '')
39
+ .split('/')[0];
40
+ if (host.startsWith('[') || host.split(':').length <= 2) {
41
+ return host;
42
+ }
43
+ return `[${host}]`;
44
+ }
45
+
35
46
  // Pattern: Normalizer - creates the endpoint host form without duplicating a supplied port.
36
47
  function requestHostWithPort(request) {
37
- const requestHost = request.hostname || request.host || request.origin;
38
- const normalizedHost = String(requestHost || '').replace(/^https?:\/\//, '');
39
- if (!request.port || normalizedHost.includes(':')) {
48
+ const normalizedHost = normalizeRequestHost(request.hostname || request.host || request.origin);
49
+ const hasExplicitPort = normalizedHost.startsWith('[')
50
+ ? normalizedHost.includes(']:')
51
+ : normalizedHost.includes(':');
52
+ if (!request.port || hasExplicitPort) {
40
53
  return normalizedHost;
41
54
  }
42
55
  return `${normalizedHost}:${request.port}`;