Skip to content

Commit 819666a

Browse files
committed
feat(logging): integrate Pino for structured logging and enhance logging capabilities
- Added comprehensive logging configuration using Pino. - Implemented default and custom logger options for FetchProxy. - Introduced structured logging for request lifecycle, security events, and performance metrics. - Enhanced tests to cover logging integration and error handling in logging. - Removed simple test file and added detailed logging examples. - Updated documentation to include logging configuration guide.
1 parent 30a622f commit 819666a

31 files changed

+2025
-541
lines changed

README.md

Lines changed: 170 additions & 73 deletions
Large diffs are not rendered by default.

SECURITY.md

Lines changed: 0 additions & 150 deletions
This file was deleted.

bun.lock

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,58 @@
33
"workspaces": {
44
"": {
55
"name": "fetch-proxy",
6+
"dependencies": {
7+
"pino": "^9.7.0",
8+
},
69
"devDependencies": {
710
"@types/bun": "latest",
11+
"@types/node": "^22.15.29",
812
"prettier": "^3.5.3",
913
},
1014
"peerDependencies": {
11-
"typescript": "^5",
15+
"typescript": "^5.8.3",
1216
},
1317
},
1418
},
1519
"packages": {
1620
"@types/bun": ["@types/bun@1.2.15", "", { "dependencies": { "bun-types": "1.2.15" } }, "sha512-U1ljPdBEphF0nw1MIk0hI7kPg7dFdPyM7EenHsp6W5loNHl7zqy6JQf/RKCgnUn2KDzUpkBwHPnEJEjII594bA=="],
1721

18-
"@types/node": ["@types/node@22.15.24", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-w9CZGm9RDjzTh/D+hFwlBJ3ziUaVw7oufKA3vOFSOZlzmW9AkZnfjPb+DLnrV6qtgL/LNmP0/2zBNCFHL3F0ng=="],
22+
"@types/node": ["@types/node@22.15.29", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-LNdjOkUDlU1RZb8e1kOIUpN1qQUlzGkEtbVNo53vbrwDg5om6oduhm4SiUaPW5ASTXhAiP0jInWG8Qx9fVlOeQ=="],
23+
24+
"atomic-sleep": ["atomic-sleep@1.0.0", "", {}, "sha512-kNOjDqAh7px0XWNI+4QbzoiR/nTkHAWNud2uvnJquD1/x5a7EQZMJT0AczqK0Qn67oY/TTQ1LbUKajZpp3I9tQ=="],
1925

2026
"bun-types": ["bun-types@1.2.15", "", { "dependencies": { "@types/node": "*" } }, "sha512-NarRIaS+iOaQU1JPfyKhZm4AsUOrwUOqRNHY0XxI8GI8jYxiLXLcdjYMG9UKS+fwWasc1uw1htV9AX24dD+p4w=="],
2127

28+
"fast-redact": ["fast-redact@3.5.0", "", {}, "sha512-dwsoQlS7h9hMeYUq1W++23NDcBLV4KqONnITDV9DjfS3q1SgDGVrBdvvTLUotWtPSD7asWDV9/CmsZPy8Hf70A=="],
29+
30+
"on-exit-leak-free": ["on-exit-leak-free@2.1.2", "", {}, "sha512-0eJJY6hXLGf1udHwfNftBqH+g73EU4B504nZeKpz1sYRKafAghwxEJunB2O7rDZkL4PGfsMVnTXZ2EjibbqcsA=="],
31+
32+
"pino": ["pino@9.7.0", "", { "dependencies": { "atomic-sleep": "^1.0.0", "fast-redact": "^3.1.1", "on-exit-leak-free": "^2.1.0", "pino-abstract-transport": "^2.0.0", "pino-std-serializers": "^7.0.0", "process-warning": "^5.0.0", "quick-format-unescaped": "^4.0.3", "real-require": "^0.2.0", "safe-stable-stringify": "^2.3.1", "sonic-boom": "^4.0.1", "thread-stream": "^3.0.0" }, "bin": { "pino": "bin.js" } }, "sha512-vnMCM6xZTb1WDmLvtG2lE/2p+t9hDEIvTWJsu6FejkE62vB7gDhvzrpFR4Cw2to+9JNQxVnkAKVPA1KPB98vWg=="],
33+
34+
"pino-abstract-transport": ["pino-abstract-transport@2.0.0", "", { "dependencies": { "split2": "^4.0.0" } }, "sha512-F63x5tizV6WCh4R6RHyi2Ml+M70DNRXt/+HANowMflpgGFMAym/VKm6G7ZOQRjqN7XbGxK1Lg9t6ZrtzOaivMw=="],
35+
36+
"pino-std-serializers": ["pino-std-serializers@7.0.0", "", {}, "sha512-e906FRY0+tV27iq4juKzSYPbUj2do2X2JX4EzSca1631EB2QJQUqGbDuERal7LCtOpxl6x3+nvo9NPZcmjkiFA=="],
37+
2238
"prettier": ["prettier@3.5.3", "", { "bin": { "prettier": "bin/prettier.cjs" } }, "sha512-QQtaxnoDJeAkDvDKWCLiwIXkTgRhwYDEQCghU9Z6q03iyek/rxRh/2lC3HB7P8sWT2xC/y5JDctPLBIGzHKbhw=="],
2339

40+
"process-warning": ["process-warning@5.0.0", "", {}, "sha512-a39t9ApHNx2L4+HBnQKqxxHNs1r7KF+Intd8Q/g1bUh6q0WIp9voPXJ/x0j+ZL45KF1pJd9+q2jLIRMfvEshkA=="],
41+
42+
"quick-format-unescaped": ["quick-format-unescaped@4.0.4", "", {}, "sha512-tYC1Q1hgyRuHgloV/YXs2w15unPVh8qfu/qCTfhTYamaw7fyhumKa2yGpdSo87vY32rIclj+4fWYQXUMs9EHvg=="],
43+
44+
"real-require": ["real-require@0.2.0", "", {}, "sha512-57frrGM/OCTLqLOAh0mhVA9VBMHd+9U7Zb2THMGdBUoZVOtGbJzjxsYGDJ3A9AYYCP4hn6y1TVbaOfzWtm5GFg=="],
45+
46+
"safe-stable-stringify": ["safe-stable-stringify@2.5.0", "", {}, "sha512-b3rppTKm9T+PsVCBEOUR46GWI7fdOs00VKZ1+9c1EWDaDMvjQc6tUwuFyIprgGgTcWoVHSKrU8H31ZHA2e0RHA=="],
47+
48+
"sonic-boom": ["sonic-boom@4.2.0", "", { "dependencies": { "atomic-sleep": "^1.0.0" } }, "sha512-INb7TM37/mAcsGmc9hyyI6+QR3rR1zVRu36B0NeGXKnOOLiZOfER5SA+N7X7k3yUYRzLWafduTDvJAfDswwEww=="],
49+
50+
"split2": ["split2@4.2.0", "", {}, "sha512-UcjcJOWknrNkF6PLX83qcHM6KHgVKNkV62Y8a5uYDVv9ydGQVwAHMKqHdJje1VTWpljG0WYpCDhrCdAOYH4TWg=="],
51+
52+
"thread-stream": ["thread-stream@3.1.0", "", { "dependencies": { "real-require": "^0.2.0" } }, "sha512-OqyPZ9u96VohAyMfJykzmivOrY2wfMSf3C5TtFJVgN+Hm6aj+voFhlK+kZEIv2FBh1X6Xp3DlnCOfEQ3B2J86A=="],
53+
2454
"typescript": ["typescript@5.8.3", "", { "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" } }, "sha512-p1diW6TqL9L07nNxvRMM7hMMw4c5XOo/1ibL4aAIGmSAt9slTE1Xgw5KWuof2uTOvCg9BY7ZRi+GaF+7sfgPeQ=="],
2555

2656
"undici-types": ["undici-types@6.21.0", "", {}, "sha512-iwDZqg0QAGrg9Rav5H4n0M64c3mkR59cJ6wQp+7C4nI0gsmExaedaYLNO44eT4AtBBwjbTiGPMlt2Md0T9H9JQ=="],
57+
58+
"bun-types/@types/node": ["@types/node@22.15.24", "", { "dependencies": { "undici-types": "~6.21.0" } }, "sha512-w9CZGm9RDjzTh/D+hFwlBJ3ziUaVw7oufKA3vOFSOZlzmW9AkZnfjPb+DLnrV6qtgL/LNmP0/2zBNCFHL3F0ng=="],
2759
}
2860
}

docs/API.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# fetch-proxy API Documentation
1+
# fetch-gate API Documentation
22

33
## Table of Contents
44

@@ -12,7 +12,7 @@
1212

1313
## Core API
1414

15-
### `createFetchProxy(options?)`
15+
### `createFetchGate(options?)`
1616

1717
Creates a new fetch proxy instance with the specified configuration.
1818

@@ -32,15 +32,15 @@ Creates a new fetch proxy instance with the specified configuration.
3232
}
3333
```
3434

35-
### `proxy(req, source?, options?)`
35+
### `proxy(req, source?, opts?)`
3636

3737
Proxies an HTTP request to the target server.
3838

3939
**Parameters:**
4040

4141
- `req: Request` - The incoming request object
4242
- `source?: string` - Target URL or path (optional if base is set)
43-
- `options?: ProxyRequestOptions` - Per-request options
43+
- `opts?: ProxyRequestOptions` - Per-request options
4444

4545
**Returns:**
4646

@@ -141,7 +141,7 @@ interface ProxyRequestOptions {
141141

142142
## Hooks
143143

144-
Hooks allow you to intercept and modify requests, responses, and handle errors. fetch-proxy provides enhanced hook naming conventions with better semantics and circuit breaker lifecycle hooks.
144+
Hooks allow you to intercept and modify requests, responses, and handle errors. fetch-gate provides enhanced hook naming conventions with better semantics and circuit breaker lifecycle hooks.
145145

146146
### Enhanced Hooks with Circuit Breaker Monitoring
147147

@@ -247,13 +247,13 @@ When multiple hooks are configured, they execute in this order:
247247

248248
```typescript
249249
const response = await proxy(request, "/users", {
250-
beforeRequest: async (req, options) => {
250+
beforeRequest: async (req, opts) => {
251251
console.log("Making request to:", req.url)
252252
},
253253
afterResponse: async (req, res, body) => {
254254
console.log("Received response:", res.status)
255255
},
256-
beforeCircuitBreakerExecution: async (req, options) => {
256+
beforeCircuitBreakerExecution: async (req, opts) => {
257257
console.log("Circuit breaker executing request")
258258
},
259259
afterCircuitBreakerExecution: async (req, result) => {
@@ -424,4 +424,4 @@ See the [examples directory](../examples/) for complete working examples:
424424
425425
- [Gateway Server](../examples/gateway-server.ts) - Basic proxy server
426426
- [Load Balancer](../examples/load-balancer.ts) - Round-robin load balancing
427-
- [Debug Script](../examples/debug.ts) - Testing and debugging
427+
- [Logging Example](../examples/logger-examples.ts) - Request/response logging

0 commit comments

Comments
 (0)