axios-interceptor-logger 1.0.0 → 1.0.1
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/README.md +15 -27
- package/dist/index.js +2 -2
- package/dist/index.mjs +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,55 +13,43 @@ This allows you to inject application-layer traffic directly into Elasticsearch/
|
|
|
13
13
|
- ⏱️ **Nanosecond Latency**: Tracks transaction duration down to the nanosecond, mapped to `event.duration`.
|
|
14
14
|
- 🔗 **Correlation IDs**: Generates (or passes through) UUID trace IDs for distributed tracing.
|
|
15
15
|
|
|
16
|
-
## Installation
|
|
16
|
+
## Installation
|
|
17
17
|
|
|
18
|
-
|
|
18
|
+
Install the package directly from npm:
|
|
19
19
|
|
|
20
|
-
### 1. Push to GitHub
|
|
21
|
-
Create a new public repository on GitHub (e.g., named `axios-interceptor-logger`), and push this code:
|
|
22
20
|
```bash
|
|
23
|
-
|
|
24
|
-
git add .
|
|
25
|
-
git commit -m "Initial commit"
|
|
26
|
-
git branch -M main
|
|
27
|
-
git remote add origin https://github.com/YOUR_GITHUB_USERNAME/axios-interceptor-logger.git
|
|
28
|
-
git push -u origin main
|
|
21
|
+
npm install axios-interceptor-logger
|
|
29
22
|
```
|
|
30
23
|
|
|
31
|
-
### 2. Install in your Consumer App
|
|
32
|
-
Once published as a public repository, you or anyone else can install it directly via npm using the GitHub URL format:
|
|
33
|
-
|
|
34
|
-
```bash
|
|
35
|
-
npm install github:YOUR_GITHUB_USERNAME/axios-interceptor-logger
|
|
36
|
-
```
|
|
37
|
-
*(Replace `YOUR_GITHUB_USERNAME` with your actual GitHub username).*
|
|
38
|
-
|
|
39
24
|
## Usage
|
|
40
25
|
|
|
41
|
-
Import the `AxiosLoggerSingleton` and attach it to your Axios instance(s).
|
|
26
|
+
Import the `AxiosLoggerSingleton` and attach it to your Axios instance(s).
|
|
42
27
|
|
|
43
28
|
```typescript
|
|
44
|
-
import axios from
|
|
45
|
-
import { AxiosLoggerSingleton } from
|
|
29
|
+
import axios from "axios";
|
|
30
|
+
import { AxiosLoggerSingleton } from "axios-interceptor-logger";
|
|
46
31
|
|
|
47
32
|
// 1. Initialize the Logger Configuration
|
|
48
33
|
const logger = AxiosLoggerSingleton.getInstance({
|
|
49
34
|
verbose: true, // Prints ECS logs to the console
|
|
50
35
|
maxPayloadBytes: 5000, // Truncates massive JSON bodies
|
|
51
|
-
redactKeys: [
|
|
52
|
-
ignoreDomains: [
|
|
36
|
+
redactKeys: ["password", "secret", "token", "authorization"],
|
|
37
|
+
ignoreDomains: ["localhost"],
|
|
53
38
|
});
|
|
54
39
|
|
|
55
40
|
// 2. Create an Axios Instance
|
|
56
41
|
const apiClient = axios.create({
|
|
57
|
-
baseURL:
|
|
42
|
+
baseURL: "https://api.example.com",
|
|
58
43
|
});
|
|
59
44
|
|
|
60
45
|
// 3. Attach the Interceptor
|
|
61
46
|
logger.attach(apiClient);
|
|
62
47
|
|
|
63
48
|
// 4. Make requests (they will now be automatically logged in ECS format!)
|
|
64
|
-
await apiClient.post(
|
|
49
|
+
await apiClient.post("/login", {
|
|
50
|
+
username: "admin",
|
|
51
|
+
password: "supersecretpassword",
|
|
52
|
+
});
|
|
65
53
|
```
|
|
66
54
|
|
|
67
55
|
## Environment Variables
|
|
@@ -78,8 +66,8 @@ The logger intercepts the traffic and outputs standard Packetbeat ECS JSON:
|
|
|
78
66
|
"ecs": { "version": "8.0.0" },
|
|
79
67
|
"agent": {
|
|
80
68
|
"name": "axios-interceptor-logger",
|
|
81
|
-
"type": "
|
|
82
|
-
"version": "1.0.
|
|
69
|
+
"type": "axios-logger",
|
|
70
|
+
"version": "1.0.1"
|
|
83
71
|
},
|
|
84
72
|
"event": {
|
|
85
73
|
"start": "2026-09-11T09:34:31.799Z",
|
package/dist/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
`;l.appendFile(this.filePath,t,r=>{r&&console.error(`Failed to write to log file: ${this.filePath}`,r)})}};var L="_axios_logging_metadata";function w(s){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s)}var T=class s{static instance;config;transport;constructor(e){this.config=e||{},this.config.customLogger?this.transport=this.config.customLogger:this.config.transportMode==="otlp"?(console.warn("OTLP transport is marked as future scope. Falling back to FileTransport."),this.transport=new c(this.config.filePath)):this.config.transportMode==="file"||!this.config.transportMode?this.transport=new c(this.config.filePath):this.transport=new c(this.config.filePath)}static getInstance(e){return s.instance||(s.instance=new s(e)),s.instance}attach(e){let t=e.interceptors.request.use(i=>this.handleRequest(i),i=>Promise.reject(i)),r=e.interceptors.response.use(i=>this.handleResponse(i),i=>this.handleError(i));return{eject:()=>{e.interceptors.request.eject(t),e.interceptors.response.eject(r)}}}isDomainIgnored(e){if(!e||!this.config.ignoreDomains)return!1;let t=e.url||"";e.baseURL&&!t.startsWith("http")&&(t=e.baseURL.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""));try{let r=new URL(t,t.startsWith("/")?"http://localhost":void 0);return this.config.ignoreDomains.includes(r.hostname)}catch{return!1}}handleRequest(e){if(this.isDomainIgnored(e))return e;let t=e.headers["X-Correlation-ID"];return(!t||!w(t))&&(t=v.default.randomUUID()),e.headers["X-Correlation-ID"]=t,e[L]={id:t,startTime:Date.now(),logged:!1},e}handleResponse(e){return this.isDomainIgnored(e.config)||this.logTransaction(e.config,e,null),e}handleError(e){if(e.config&&this.isDomainIgnored(e.config))return Promise.reject(e);let t=e.config,r,i=!1;if(t&&(r=t[L]),!r){let n;t&&t.headers&&t.headers["X-Correlation-ID"]?n=t.headers["X-Correlation-ID"]:e.response&&e.response.config&&e.response.config.headers["X-Correlation-ID"]?n=e.response.config.headers["X-Correlation-ID"]:e.request&&typeof e.request.getHeader=="function"&&(n=e.request.getHeader("X-Correlation-ID")),(!n||!w(n))&&(n=v.default.randomUUID(),i=!0),r={id:n,startTime:Date.now(),logged:!1},t&&(t[L]=r)}return this.logTransaction(t,e.response,e,i),Promise.reject(e)}logTransaction(e,t,r,i=!1){if(!e)return;let n=e[L];if(!n||n.logged)return;n.logged=!0;let u=Date.now()-n.startTime,a=e.url||"";e.baseURL&&!a.startsWith("http")&&(a=e.baseURL.replace(/\/+$/,"")+"/"+a.replace(/^\/+/,""));let o,f;try{o=new URL(a,a.startsWith("/")?"http://localhost":void 0),o.port&&(f=parseInt(o.port,10))}catch{}let A=e.headers?g({...e.headers},this.config.redactKeys,this.config.maxPayloadBytes):{},I;A["content-length"]?I=parseInt(A["content-length"],10):e.data&&typeof e.data=="string"&&(I=Buffer.byteLength(e.data,"utf8"));let E=new Date().toISOString(),B=new Date(n.startTime).toISOString(),
|
|
1
|
+
"use strict";var k=Object.create;var h=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var U=Object.getOwnPropertyNames;var q=Object.getPrototypeOf,b=Object.prototype.hasOwnProperty;var N=(s,e)=>{for(var t in e)h(s,t,{get:e[t],enumerable:!0})},C=(s,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of U(e))!b.call(s,i)&&i!==t&&h(s,i,{get:()=>e[i],enumerable:!(r=P(e,i))||r.enumerable});return s};var D=(s,e,t)=>(t=s!=null?k(q(s)):{},C(e||!s||!s.__esModule?h(t,"default",{value:s,enumerable:!0}):t,s)),O=s=>C(h({},"__esModule",{value:!0}),s);var M={};N(M,{AxiosLoggerSingleton:()=>T});module.exports=O(M);var v=D(require("crypto"));function g(s,e=["authorization","password","token","secret","cookie"],t=10240){let r=new WeakSet;function i(n,u=0){if(n==null)return n;if(typeof n!="object"&&typeof n!="function")return typeof n=="string"&&Buffer.byteLength(n,"utf8")>t?n.substring(0,t/2)+`... [TRUNCATED ${Buffer.byteLength(n,"utf8")-t/2} BYTES]`:n;if(Buffer.isBuffer(n)||n instanceof ArrayBuffer||typeof Blob<"u"&&n instanceof Blob){let o=Buffer.isBuffer(n)?"Buffer":n instanceof ArrayBuffer?"ArrayBuffer":"Blob",f=n.byteLength||n.size||0;return{"[BINARY_DATA]":`<Type: ${o}, Size: ${f} bytes>`}}if(r.has(n))return"[CIRCULAR_REFERENCE]";if(r.add(n),Array.isArray(n))return n.map(o=>i(o,u+1));let a={};for(let o of Object.keys(n))e.some(f=>o.toLowerCase().includes(f.toLowerCase()))?a[o]="[REDACTED]":a[o]=i(n[o],u+1);return r.delete(n),a}try{let n=JSON.stringify(s);if(n&&Buffer.byteLength(n,"utf8")>t*2)return{"[TRUNCATED_NESTED_DEPTH]":!0}}catch{}return i(s)}var m=class{log(e){console.log(JSON.stringify(e,null,2))}};var l=D(require("fs")),y=D(require("path")),c=class{filePath;constructor(e){this.filePath=e||y.join(process.cwd(),"logs","http-transactions.log"),this.ensureDirectoryExists(this.filePath)}ensureDirectoryExists(e){let t=y.dirname(e);l.existsSync(t)||l.mkdirSync(t,{recursive:!0})}log(e){let t=JSON.stringify(e)+`
|
|
2
|
+
`;l.appendFile(this.filePath,t,r=>{r&&console.error(`Failed to write to log file: ${this.filePath}`,r)})}};var L="_axios_logging_metadata";function w(s){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(s)}var T=class s{static instance;config;transport;constructor(e){this.config=e||{},this.config.customLogger?this.transport=this.config.customLogger:this.config.transportMode==="otlp"?(console.warn("OTLP transport is marked as future scope. Falling back to FileTransport."),this.transport=new c(this.config.filePath)):this.config.transportMode==="file"||!this.config.transportMode?this.transport=new c(this.config.filePath):this.transport=new c(this.config.filePath)}static getInstance(e){return s.instance||(s.instance=new s(e)),s.instance}attach(e){let t=e.interceptors.request.use(i=>this.handleRequest(i),i=>Promise.reject(i)),r=e.interceptors.response.use(i=>this.handleResponse(i),i=>this.handleError(i));return{eject:()=>{e.interceptors.request.eject(t),e.interceptors.response.eject(r)}}}isDomainIgnored(e){if(!e||!this.config.ignoreDomains)return!1;let t=e.url||"";e.baseURL&&!t.startsWith("http")&&(t=e.baseURL.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""));try{let r=new URL(t,t.startsWith("/")?"http://localhost":void 0);return this.config.ignoreDomains.includes(r.hostname)}catch{return!1}}handleRequest(e){if(this.isDomainIgnored(e))return e;let t=e.headers["X-Correlation-ID"];return(!t||!w(t))&&(t=v.default.randomUUID()),e.headers["X-Correlation-ID"]=t,e[L]={id:t,startTime:Date.now(),logged:!1},e}handleResponse(e){return this.isDomainIgnored(e.config)||this.logTransaction(e.config,e,null),e}handleError(e){if(e.config&&this.isDomainIgnored(e.config))return Promise.reject(e);let t=e.config,r,i=!1;if(t&&(r=t[L]),!r){let n;t&&t.headers&&t.headers["X-Correlation-ID"]?n=t.headers["X-Correlation-ID"]:e.response&&e.response.config&&e.response.config.headers["X-Correlation-ID"]?n=e.response.config.headers["X-Correlation-ID"]:e.request&&typeof e.request.getHeader=="function"&&(n=e.request.getHeader("X-Correlation-ID")),(!n||!w(n))&&(n=v.default.randomUUID(),i=!0),r={id:n,startTime:Date.now(),logged:!1},t&&(t[L]=r)}return this.logTransaction(t,e.response,e,i),Promise.reject(e)}logTransaction(e,t,r,i=!1){if(!e)return;let n=e[L];if(!n||n.logged)return;n.logged=!0;let u=Date.now()-n.startTime,a=e.url||"";e.baseURL&&!a.startsWith("http")&&(a=e.baseURL.replace(/\/+$/,"")+"/"+a.replace(/^\/+/,""));let o,f;try{o=new URL(a,a.startsWith("/")?"http://localhost":void 0),o.port&&(f=parseInt(o.port,10))}catch{}let A=e.headers?g({...e.headers},this.config.redactKeys,this.config.maxPayloadBytes):{},I;A["content-length"]?I=parseInt(A["content-length"],10):e.data&&typeof e.data=="string"&&(I=Buffer.byteLength(e.data,"utf8"));let E=new Date().toISOString(),B=new Date(n.startTime).toISOString(),S=u*1e6,R=o?o.hostname:"unknown",p={"@timestamp":E,ecs:{version:"8.0.0"},agent:{name:"axios-interceptor-logger",type:"axios-logger",version:"1.0.1"},event:{start:B,end:E,duration:S,kind:"event",category:["network"],type:["connection","protocol"],dataset:"http"},http:{request:{method:(e.method||"GET").toUpperCase(),bytes:I,headers:A,body:e.data?{content:g(e.data,this.config.redactKeys,this.config.maxPayloadBytes)}:void 0},version:"1.1"},url:{full:a,path:o?o.pathname:a,query:o&&o.search?o.search.replace("?",""):void 0,scheme:o?o.protocol.replace(":",""):"unknown",domain:R,port:f},source:{domain:typeof process<"u"&&process.env&&process.env.APP_HOST?process.env.APP_HOST:"localhost"},destination:{domain:R},server:{domain:R},network:{protocol:"http"},status:r?"Error":"OK","trace.id":n.id};if(t){let d=t.headers?g({...t.headers},this.config.redactKeys,this.config.maxPayloadBytes):{},x;d["content-length"]?x=parseInt(d["content-length"],10):t.data&&typeof t.data=="string"&&(x=Buffer.byteLength(t.data,"utf8")),p.http.response={status_code:t.status,headers:d,body:t.data?{content:g(t.data,this.config.redactKeys,this.config.maxPayloadBytes)}:void 0,bytes:x}}r&&(p.error={message:r.message,code:r.code||r.code}),this.config.verbose&&new m().log(p),this.transport.log(p)}};0&&(module.exports={AxiosLoggerSingleton});
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import D from"crypto";function g(o,e=["authorization","password","token","secret","cookie"],t=10240){let s=new WeakSet;function i(n,u=0){if(n==null)return n;if(typeof n!="object"&&typeof n!="function")return typeof n=="string"&&Buffer.byteLength(n,"utf8")>t?n.substring(0,t/2)+`... [TRUNCATED ${Buffer.byteLength(n,"utf8")-t/2} BYTES]`:n;if(Buffer.isBuffer(n)||n instanceof ArrayBuffer||typeof Blob<"u"&&n instanceof Blob){let r=Buffer.isBuffer(n)?"Buffer":n instanceof ArrayBuffer?"ArrayBuffer":"Blob",f=n.byteLength||n.size||0;return{"[BINARY_DATA]":`<Type: ${r}, Size: ${f} bytes>`}}if(s.has(n))return"[CIRCULAR_REFERENCE]";if(s.add(n),Array.isArray(n))return n.map(r=>i(r,u+1));let a={};for(let r of Object.keys(n))e.some(f=>r.toLowerCase().includes(f.toLowerCase()))?a[r]="[REDACTED]":a[r]=i(n[r],u+1);return s.delete(n),a}try{let n=JSON.stringify(o);if(n&&Buffer.byteLength(n,"utf8")>t*2)return{"[TRUNCATED_NESTED_DEPTH]":!0}}catch{}return i(o)}var h=class{log(e){console.log(JSON.stringify(e,null,2))}};import*as l from"fs";import*as m from"path";var c=class{filePath;constructor(e){this.filePath=e||m.join(process.cwd(),"logs","http-transactions.log"),this.ensureDirectoryExists(this.filePath)}ensureDirectoryExists(e){let t=m.dirname(e);l.existsSync(t)||l.mkdirSync(t,{recursive:!0})}log(e){let t=JSON.stringify(e)+`
|
|
2
|
-
`;l.appendFile(this.filePath,t,s=>{s&&console.error(`Failed to write to log file: ${this.filePath}`,s)})}};var y="_axios_logging_metadata";function v(o){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o)}var R=class o{static instance;config;transport;constructor(e){this.config=e||{},this.config.customLogger?this.transport=this.config.customLogger:this.config.transportMode==="otlp"?(console.warn("OTLP transport is marked as future scope. Falling back to FileTransport."),this.transport=new c(this.config.filePath)):this.config.transportMode==="file"||!this.config.transportMode?this.transport=new c(this.config.filePath):this.transport=new c(this.config.filePath)}static getInstance(e){return o.instance||(o.instance=new o(e)),o.instance}attach(e){let t=e.interceptors.request.use(i=>this.handleRequest(i),i=>Promise.reject(i)),s=e.interceptors.response.use(i=>this.handleResponse(i),i=>this.handleError(i));return{eject:()=>{e.interceptors.request.eject(t),e.interceptors.response.eject(s)}}}isDomainIgnored(e){if(!e||!this.config.ignoreDomains)return!1;let t=e.url||"";e.baseURL&&!t.startsWith("http")&&(t=e.baseURL.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""));try{let s=new URL(t,t.startsWith("/")?"http://localhost":void 0);return this.config.ignoreDomains.includes(s.hostname)}catch{return!1}}handleRequest(e){if(this.isDomainIgnored(e))return e;let t=e.headers["X-Correlation-ID"];return(!t||!v(t))&&(t=D.randomUUID()),e.headers["X-Correlation-ID"]=t,e[y]={id:t,startTime:Date.now(),logged:!1},e}handleResponse(e){return this.isDomainIgnored(e.config)||this.logTransaction(e.config,e,null),e}handleError(e){if(e.config&&this.isDomainIgnored(e.config))return Promise.reject(e);let t=e.config,s,i=!1;if(t&&(s=t[y]),!s){let n;t&&t.headers&&t.headers["X-Correlation-ID"]?n=t.headers["X-Correlation-ID"]:e.response&&e.response.config&&e.response.config.headers["X-Correlation-ID"]?n=e.response.config.headers["X-Correlation-ID"]:e.request&&typeof e.request.getHeader=="function"&&(n=e.request.getHeader("X-Correlation-ID")),(!n||!v(n))&&(n=D.randomUUID(),i=!0),s={id:n,startTime:Date.now(),logged:!1},t&&(t[y]=s)}return this.logTransaction(t,e.response,e,i),Promise.reject(e)}logTransaction(e,t,s,i=!1){if(!e)return;let n=e[y];if(!n||n.logged)return;n.logged=!0;let u=Date.now()-n.startTime,a=e.url||"";e.baseURL&&!a.startsWith("http")&&(a=e.baseURL.replace(/\/+$/,"")+"/"+a.replace(/^\/+/,""));let r,f;try{r=new URL(a,a.startsWith("/")?"http://localhost":void 0),r.port&&(f=parseInt(r.port,10))}catch{}let L=e.headers?g({...e.headers},this.config.redactKeys,this.config.maxPayloadBytes):{},T;L["content-length"]?T=parseInt(L["content-length"],10):e.data&&typeof e.data=="string"&&(T=Buffer.byteLength(e.data,"utf8"));let x=new Date().toISOString(),E=new Date(n.startTime).toISOString(),C=u*1e6,A=r?r.hostname:"unknown",p={"@timestamp":x,ecs:{version:"8.0.0"},agent:{name:"axios-interceptor-logger",type:"
|
|
2
|
+
`;l.appendFile(this.filePath,t,s=>{s&&console.error(`Failed to write to log file: ${this.filePath}`,s)})}};var y="_axios_logging_metadata";function v(o){return/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i.test(o)}var R=class o{static instance;config;transport;constructor(e){this.config=e||{},this.config.customLogger?this.transport=this.config.customLogger:this.config.transportMode==="otlp"?(console.warn("OTLP transport is marked as future scope. Falling back to FileTransport."),this.transport=new c(this.config.filePath)):this.config.transportMode==="file"||!this.config.transportMode?this.transport=new c(this.config.filePath):this.transport=new c(this.config.filePath)}static getInstance(e){return o.instance||(o.instance=new o(e)),o.instance}attach(e){let t=e.interceptors.request.use(i=>this.handleRequest(i),i=>Promise.reject(i)),s=e.interceptors.response.use(i=>this.handleResponse(i),i=>this.handleError(i));return{eject:()=>{e.interceptors.request.eject(t),e.interceptors.response.eject(s)}}}isDomainIgnored(e){if(!e||!this.config.ignoreDomains)return!1;let t=e.url||"";e.baseURL&&!t.startsWith("http")&&(t=e.baseURL.replace(/\/+$/,"")+"/"+t.replace(/^\/+/,""));try{let s=new URL(t,t.startsWith("/")?"http://localhost":void 0);return this.config.ignoreDomains.includes(s.hostname)}catch{return!1}}handleRequest(e){if(this.isDomainIgnored(e))return e;let t=e.headers["X-Correlation-ID"];return(!t||!v(t))&&(t=D.randomUUID()),e.headers["X-Correlation-ID"]=t,e[y]={id:t,startTime:Date.now(),logged:!1},e}handleResponse(e){return this.isDomainIgnored(e.config)||this.logTransaction(e.config,e,null),e}handleError(e){if(e.config&&this.isDomainIgnored(e.config))return Promise.reject(e);let t=e.config,s,i=!1;if(t&&(s=t[y]),!s){let n;t&&t.headers&&t.headers["X-Correlation-ID"]?n=t.headers["X-Correlation-ID"]:e.response&&e.response.config&&e.response.config.headers["X-Correlation-ID"]?n=e.response.config.headers["X-Correlation-ID"]:e.request&&typeof e.request.getHeader=="function"&&(n=e.request.getHeader("X-Correlation-ID")),(!n||!v(n))&&(n=D.randomUUID(),i=!0),s={id:n,startTime:Date.now(),logged:!1},t&&(t[y]=s)}return this.logTransaction(t,e.response,e,i),Promise.reject(e)}logTransaction(e,t,s,i=!1){if(!e)return;let n=e[y];if(!n||n.logged)return;n.logged=!0;let u=Date.now()-n.startTime,a=e.url||"";e.baseURL&&!a.startsWith("http")&&(a=e.baseURL.replace(/\/+$/,"")+"/"+a.replace(/^\/+/,""));let r,f;try{r=new URL(a,a.startsWith("/")?"http://localhost":void 0),r.port&&(f=parseInt(r.port,10))}catch{}let L=e.headers?g({...e.headers},this.config.redactKeys,this.config.maxPayloadBytes):{},T;L["content-length"]?T=parseInt(L["content-length"],10):e.data&&typeof e.data=="string"&&(T=Buffer.byteLength(e.data,"utf8"));let x=new Date().toISOString(),E=new Date(n.startTime).toISOString(),C=u*1e6,A=r?r.hostname:"unknown",p={"@timestamp":x,ecs:{version:"8.0.0"},agent:{name:"axios-interceptor-logger",type:"axios-logger",version:"1.0.1"},event:{start:E,end:x,duration:C,kind:"event",category:["network"],type:["connection","protocol"],dataset:"http"},http:{request:{method:(e.method||"GET").toUpperCase(),bytes:T,headers:L,body:e.data?{content:g(e.data,this.config.redactKeys,this.config.maxPayloadBytes)}:void 0},version:"1.1"},url:{full:a,path:r?r.pathname:a,query:r&&r.search?r.search.replace("?",""):void 0,scheme:r?r.protocol.replace(":",""):"unknown",domain:A,port:f},source:{domain:typeof process<"u"&&process.env&&process.env.APP_HOST?process.env.APP_HOST:"localhost"},destination:{domain:A},server:{domain:A},network:{protocol:"http"},status:s?"Error":"OK","trace.id":n.id};if(t){let d=t.headers?g({...t.headers},this.config.redactKeys,this.config.maxPayloadBytes):{},I;d["content-length"]?I=parseInt(d["content-length"],10):t.data&&typeof t.data=="string"&&(I=Buffer.byteLength(t.data,"utf8")),p.http.response={status_code:t.status,headers:d,body:t.data?{content:g(t.data,this.config.redactKeys,this.config.maxPayloadBytes)}:void 0,bytes:I}}s&&(p.error={message:s.message,code:s.code||s.code}),this.config.verbose&&new h().log(p),this.transport.log(p)}};export{R as AxiosLoggerSingleton};
|