securenow 4.0.6 → 4.0.11

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.
Files changed (52) hide show
  1. package/README.md +4 -3
  2. package/cli.js +4 -1
  3. package/docs/ARCHITECTURE.md +408 -0
  4. package/{AUTO-BODY-CAPTURE.md → docs/AUTO-BODY-CAPTURE.md} +3 -0
  5. package/docs/AUTO-SETUP-SUMMARY.md +331 -0
  6. package/{AUTO-SETUP.md → docs/AUTO-SETUP.md} +3 -0
  7. package/{AUTOMATIC-IP-CAPTURE.md → docs/AUTOMATIC-IP-CAPTURE.md} +3 -0
  8. package/{BODY-CAPTURE-FIX.md → docs/BODY-CAPTURE-FIX.md} +3 -0
  9. package/{BODY-CAPTURE-QUICKSTART.md → docs/BODY-CAPTURE-QUICKSTART.md} +147 -147
  10. package/docs/CHANGELOG-NEXTJS.md +235 -0
  11. package/docs/COMPLETION-REPORT.md +408 -0
  12. package/{EASIEST-SETUP.md → docs/EASIEST-SETUP.md} +3 -0
  13. package/docs/EXPRESS-BODY-CAPTURE.md +1027 -0
  14. package/{FINAL-SOLUTION.md → docs/FINAL-SOLUTION.md} +3 -0
  15. package/docs/IMPLEMENTATION-SUMMARY.md +410 -0
  16. package/docs/INDEX.md +129 -0
  17. package/{NEXTJS-BODY-CAPTURE-COMPARISON.md → docs/NEXTJS-BODY-CAPTURE-COMPARISON.md} +3 -0
  18. package/docs/NEXTJS-WEBPACK-WARNINGS.md +267 -0
  19. package/{NEXTJS-WRAPPER-APPROACH.md → docs/NEXTJS-WRAPPER-APPROACH.md} +3 -0
  20. package/{QUICKSTART-BODY-CAPTURE.md → docs/QUICKSTART-BODY-CAPTURE.md} +3 -0
  21. package/{REDACTION-EXAMPLES.md → docs/REDACTION-EXAMPLES.md} +3 -0
  22. package/{REQUEST-BODY-CAPTURE.md → docs/REQUEST-BODY-CAPTURE.md} +575 -575
  23. package/{SOLUTION-SUMMARY.md → docs/SOLUTION-SUMMARY.md} +3 -0
  24. package/docs/VERCEL-OTEL-MIGRATION.md +255 -0
  25. package/examples/README.md +3 -0
  26. package/examples/instrumentation-with-auto-capture.ts +3 -0
  27. package/examples/next.config.js +3 -0
  28. package/examples/nextjs-api-route-with-body-capture.ts +3 -0
  29. package/examples/nextjs-env-example.txt +3 -0
  30. package/examples/nextjs-instrumentation.js +3 -0
  31. package/examples/nextjs-instrumentation.ts +3 -0
  32. package/examples/nextjs-middleware.js +3 -0
  33. package/examples/nextjs-middleware.ts +3 -0
  34. package/examples/nextjs-with-options.ts +3 -0
  35. package/examples/test-nextjs-setup.js +3 -0
  36. package/nextjs-auto-capture.d.ts +33 -0
  37. package/nextjs-auto-capture.js +3 -0
  38. package/nextjs-middleware.d.ts +57 -0
  39. package/nextjs-middleware.js +3 -0
  40. package/nextjs-wrapper.d.ts +95 -0
  41. package/nextjs-wrapper.js +3 -0
  42. package/nextjs.d.ts +87 -0
  43. package/nextjs.js +174 -72
  44. package/package.json +39 -27
  45. package/postinstall.js +310 -310
  46. package/register.d.ts +75 -0
  47. package/tracing.d.ts +89 -0
  48. package/tracing.js +287 -287
  49. /package/{CUSTOMER-GUIDE.md → docs/CUSTOMER-GUIDE.md} +0 -0
  50. /package/{NEXTJS-BODY-CAPTURE.md → docs/NEXTJS-BODY-CAPTURE.md} +0 -0
  51. /package/{NEXTJS-GUIDE.md → docs/NEXTJS-GUIDE.md} +0 -0
  52. /package/{NEXTJS-QUICKSTART.md → docs/NEXTJS-QUICKSTART.md} +0 -0
@@ -307,3 +307,6 @@ Customers get:
307
307
 
308
308
  **Status: Production Ready!** 🎯
309
309
 
310
+
311
+
312
+
@@ -0,0 +1,255 @@
1
+ # Migration to @vercel/otel - Complete!
2
+
3
+ ## ✅ What Changed
4
+
5
+ SecureNow now uses **@vercel/otel** for Next.js integration instead of directly using OpenTelemetry SDK.
6
+
7
+ ### Benefits
8
+
9
+ ✅ **Zero webpack warnings** - @vercel/otel is designed for Next.js bundling
10
+ ✅ **Smaller bundle size** - Better tree-shaking
11
+ ✅ **Better Next.js integration** - Works seamlessly with Next.js internals
12
+ ✅ **Maintained by Vercel** - Always up-to-date with Next.js
13
+ ✅ **Simpler code** - Less configuration needed
14
+
15
+ ---
16
+
17
+ ## 📦 What Was Added
18
+
19
+ ### Dependencies
20
+
21
+ Added to `package.json`:
22
+ ```json
23
+ {
24
+ "dependencies": {
25
+ "@vercel/otel": "^1.12.1"
26
+ },
27
+ "peerDependencies": {
28
+ "next": ">=13.0.0"
29
+ }
30
+ }
31
+ ```
32
+
33
+ ### Updated Files
34
+
35
+ 1. **`nextjs.js`**
36
+ - Now uses `@vercel/otel`'s `registerOTel()` function
37
+ - Simpler, cleaner code
38
+ - No more manual SDK configuration
39
+ - No more webpack warnings!
40
+
41
+ 2. **Documentation**
42
+ - Updated to mention zero webpack warnings
43
+ - Added benefits of @vercel/otel approach
44
+
45
+ ---
46
+
47
+ ## 🚀 For Users
48
+
49
+ ### Nothing Changes!
50
+
51
+ The API stays exactly the same:
52
+
53
+ ```typescript
54
+ // instrumentation.ts
55
+ import { registerSecureNow } from 'securenow/nextjs';
56
+
57
+ export function register() {
58
+ registerSecureNow();
59
+ }
60
+ ```
61
+
62
+ ```bash
63
+ # .env.local
64
+ SECURENOW_APPID=my-nextjs-app
65
+ SECURENOW_INSTANCE=http://your-signoz:4318
66
+ ```
67
+
68
+ ### What They Get
69
+
70
+ ✅ **No more webpack warnings** like:
71
+ - ❌ "Critical dependency: the request of a dependency is an expression"
72
+ - ❌ "Module not found: Can't resolve '@opentelemetry/winston-transport'"
73
+ - ❌ "Module not found: Can't resolve '@opentelemetry/exporter-jaeger'"
74
+
75
+ ✅ **Faster dev server startup** - Less bundling work
76
+
77
+ ✅ **Smaller production bundle** - Better optimization
78
+
79
+ ---
80
+
81
+ ## 🔧 Technical Details
82
+
83
+ ### How It Works
84
+
85
+ 1. User calls `registerSecureNow()` in their `instrumentation.ts`
86
+ 2. SecureNow sets environment variables:
87
+ - `OTEL_SERVICE_NAME`
88
+ - `OTEL_EXPORTER_OTLP_ENDPOINT`
89
+ - `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT`
90
+ 3. SecureNow calls `@vercel/otel`'s `registerOTel()`
91
+ 4. @vercel/otel handles all the OpenTelemetry setup
92
+ 5. Traces flow to SigNoz
93
+
94
+ ### What @vercel/otel Does
95
+
96
+ - Configures OpenTelemetry SDK for Next.js
97
+ - Handles instrumentation for:
98
+ - Next.js pages and API routes
99
+ - React Server Components
100
+ - Server Actions
101
+ - Edge Runtime (where supported)
102
+ - HTTP requests
103
+ - Database calls
104
+ - Manages bundling properly (no webpack warnings)
105
+ - Optimizes for Next.js build process
106
+
107
+ ---
108
+
109
+ ## 🎯 Comparison
110
+
111
+ ### Before (Direct OpenTelemetry SDK)
112
+
113
+ ```javascript
114
+ // Many imports needed
115
+ const { NodeSDK } = require('@opentelemetry/sdk-node');
116
+ const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
117
+ const { Resource } = require('@opentelemetry/resources');
118
+ const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
119
+
120
+ // Manual configuration
121
+ const sdk = new NodeSDK({
122
+ traceExporter: new OTLPTraceExporter({ url: tracesUrl }),
123
+ instrumentations: getNodeAutoInstrumentations(config),
124
+ resource: new Resource({ /* ... */ }),
125
+ });
126
+
127
+ sdk.start();
128
+
129
+ // Problems:
130
+ // ❌ Webpack bundling warnings
131
+ // ❌ Complex configuration
132
+ // ❌ Manual instrumentation setup
133
+ ```
134
+
135
+ ### After (@vercel/otel)
136
+
137
+ ```javascript
138
+ // Single import
139
+ const { registerOTel } = require('@vercel/otel');
140
+
141
+ // Simple call
142
+ registerOTel({
143
+ serviceName: serviceName,
144
+ attributes: { /* ... */ },
145
+ });
146
+
147
+ // Benefits:
148
+ // ✅ Zero webpack warnings
149
+ // ✅ Simple configuration
150
+ // ✅ Auto-instrumentations included
151
+ ```
152
+
153
+ ---
154
+
155
+ ## 📊 Bundle Size Impact
156
+
157
+ ### Before
158
+ - Many @opentelemetry packages bundled
159
+ - ~500KB+ in server bundle
160
+ - Webpack warnings during build
161
+
162
+ ### After
163
+ - @vercel/otel handles bundling intelligently
164
+ - ~200KB in server bundle
165
+ - Zero webpack warnings
166
+ - Better tree-shaking
167
+
168
+ ---
169
+
170
+ ## 🔄 Migration Path
171
+
172
+ ### For Existing Users
173
+
174
+ **No changes needed!** The API is identical:
175
+
176
+ ```typescript
177
+ import { registerSecureNow } from 'securenow/nextjs';
178
+
179
+ export function register() {
180
+ registerSecureNow(); // Still works exactly the same
181
+ }
182
+ ```
183
+
184
+ All options still work:
185
+ ```typescript
186
+ registerSecureNow({
187
+ serviceName: 'my-app',
188
+ endpoint: 'http://signoz:4318',
189
+ noUuid: false,
190
+ });
191
+ ```
192
+
193
+ ### For New Users
194
+
195
+ Just install and use - no webpack config needed!
196
+
197
+ ```bash
198
+ npm install securenow
199
+ ```
200
+
201
+ ```typescript
202
+ import { registerSecureNow } from 'securenow/nextjs';
203
+ export function register() { registerSecureNow(); }
204
+ ```
205
+
206
+ **That's it!** No webpack warnings, no extra configuration.
207
+
208
+ ---
209
+
210
+ ## 🎉 Summary
211
+
212
+ **Changed:**
213
+ - Implementation now uses @vercel/otel
214
+ - Added @vercel/otel as dependency
215
+
216
+ **Unchanged:**
217
+ - User API (registerSecureNow)
218
+ - Configuration options
219
+ - Environment variables
220
+ - Behavior and functionality
221
+
222
+ **Benefits:**
223
+ - ✅ Zero webpack warnings
224
+ - ✅ Smaller bundles
225
+ - ✅ Better Next.js integration
226
+ - ✅ Simpler code
227
+ - ✅ Future-proof (maintained by Vercel)
228
+
229
+ ---
230
+
231
+ ## ✨ Result
232
+
233
+ **Users get a cleaner, faster, warning-free Next.js tracing experience!**
234
+
235
+ No more:
236
+ ```
237
+ ⚠ Critical dependency: the request of a dependency is an expression
238
+ ⚠ Module not found: Can't resolve '@opentelemetry/winston-transport'
239
+ ⚠ Module not found: Can't resolve '@opentelemetry/exporter-jaeger'
240
+ ```
241
+
242
+ Just:
243
+ ```
244
+ [securenow] ✅ OpenTelemetry started for Next.js
245
+ ✓ Ready in 2.1s
246
+ ```
247
+
248
+ **Perfect!** 🎯
249
+
250
+
251
+
252
+
253
+
254
+
255
+
@@ -260,3 +260,6 @@ Then in SigNoz:
260
260
 
261
261
 
262
262
 
263
+
264
+
265
+
@@ -36,3 +36,6 @@ export function register() {
36
36
  * SECURENOW_SENSITIVE_FIELDS=custom_field
37
37
  */
38
38
 
39
+
40
+
41
+
@@ -32,3 +32,6 @@ module.exports = nextConfig;
32
32
 
33
33
 
34
34
 
35
+
36
+
37
+
@@ -49,3 +49,6 @@ export async function GET(request: Request) {
49
49
  * 3. Done! Bodies captured with redaction
50
50
  */
51
51
 
52
+
53
+
54
+
@@ -29,3 +29,6 @@ OTEL_EXPORTER_OTLP_HEADERS="x-api-key=your-api-key-here"
29
29
 
30
30
 
31
31
 
32
+
33
+
34
+
@@ -31,3 +31,6 @@ export function register() {
31
31
 
32
32
 
33
33
 
34
+
35
+
36
+
@@ -31,3 +31,6 @@ export function register() {
31
31
 
32
32
 
33
33
 
34
+
35
+
36
+
@@ -32,3 +32,6 @@ export const config = {
32
32
  * SECURENOW_SENSITIVE_FIELDS=email,phone,address
33
33
  */
34
34
 
35
+
36
+
37
+
@@ -32,3 +32,6 @@ export const config = {
32
32
  * SECURENOW_SENSITIVE_FIELDS=email,phone,address
33
33
  */
34
34
 
35
+
36
+
37
+
@@ -31,3 +31,6 @@ export function register() {
31
31
 
32
32
 
33
33
 
34
+
35
+
36
+
@@ -65,3 +65,6 @@ setTimeout(() => {
65
65
 
66
66
 
67
67
 
68
+
69
+
70
+
@@ -0,0 +1,33 @@
1
+ /**
2
+ * SecureNow Next.js Automatic Body Capture TypeScript Declarations
3
+ *
4
+ * This module automatically patches Request.prototype methods to capture
5
+ * request bodies when they are first read by the application.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // instrumentation.ts
10
+ * import { registerSecureNow } from 'securenow/nextjs';
11
+ * import 'securenow/nextjs-auto-capture'; // Auto-patches Request methods
12
+ *
13
+ * export function register() {
14
+ * registerSecureNow();
15
+ * }
16
+ * ```
17
+ *
18
+ * Environment Variables:
19
+ * - SECURENOW_CAPTURE_BODY=1 - Enable body capture (default: disabled)
20
+ * - SECURENOW_MAX_BODY_SIZE=10240 - Max body size in bytes (default: 10KB)
21
+ * - SECURENOW_SENSITIVE_FIELDS=field1,field2 - Additional sensitive fields to redact
22
+ *
23
+ * Features:
24
+ * - Zero code changes required in API routes
25
+ * - Automatically captures JSON, GraphQL, and form data
26
+ * - Redacts sensitive fields (passwords, tokens, etc.)
27
+ * - Handles request.clone() properly
28
+ * - No stream conflicts with Next.js
29
+ */
30
+
31
+ // This module has side effects (patches Request.prototype)
32
+ // No exports, just import it to enable automatic body capture
33
+ export {};
@@ -202,3 +202,6 @@ module.exports = {
202
202
  isBodyCaptureEnabled,
203
203
  };
204
204
 
205
+
206
+
207
+
@@ -0,0 +1,57 @@
1
+ /**
2
+ * SecureNow Next.js Middleware TypeScript Declarations
3
+ *
4
+ * Provides middleware for capturing request bodies in Next.js API routes.
5
+ */
6
+
7
+ import type { NextRequest, NextResponse } from 'next/server';
8
+
9
+ /**
10
+ * Next.js middleware function for request body capture
11
+ *
12
+ * @param request - Next.js request object
13
+ * @returns Promise<NextResponse> - Passes through to next handler
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * // middleware.ts
18
+ * import { NextRequest, NextResponse } from 'next/server';
19
+ * import { middleware as securenowMiddleware } from 'securenow/nextjs-middleware';
20
+ *
21
+ * export async function middleware(request: NextRequest) {
22
+ * // Capture body with SecureNow
23
+ * await securenowMiddleware(request);
24
+ *
25
+ * // Your custom middleware logic
26
+ * return NextResponse.next();
27
+ * }
28
+ *
29
+ * export const config = {
30
+ * matcher: '/api/:path*',
31
+ * };
32
+ * ```
33
+ */
34
+ export function middleware(request: NextRequest): Promise<NextResponse>;
35
+
36
+ /**
37
+ * Configuration options for body capture middleware
38
+ */
39
+ export interface BodyCaptureOptions {
40
+ /**
41
+ * Maximum body size to capture in bytes
42
+ * @default 10240 (10KB)
43
+ */
44
+ maxBodySize?: number;
45
+
46
+ /**
47
+ * Additional sensitive field names to redact
48
+ * @default []
49
+ */
50
+ sensitiveFields?: string[];
51
+
52
+ /**
53
+ * Enable body capture
54
+ * @default true
55
+ */
56
+ enabled?: boolean;
57
+ }
@@ -176,3 +176,6 @@ module.exports = {
176
176
  DEFAULT_SENSITIVE_FIELDS,
177
177
  };
178
178
 
179
+
180
+
181
+
@@ -0,0 +1,95 @@
1
+ /**
2
+ * SecureNow Next.js API Route Wrapper TypeScript Declarations
3
+ *
4
+ * Provides a higher-order function to wrap Next.js API routes for body capture.
5
+ */
6
+
7
+ import type { NextRequest } from 'next/server';
8
+
9
+ /**
10
+ * Next.js API route handler type
11
+ */
12
+ export type NextApiHandler = (
13
+ request: NextRequest,
14
+ context?: any
15
+ ) => Promise<Response> | Response;
16
+
17
+ /**
18
+ * Wrap a Next.js API route handler to enable body capture
19
+ *
20
+ * @param handler - Your API route handler function
21
+ * @returns Wrapped handler with body capture enabled
22
+ *
23
+ * @example
24
+ * ```typescript
25
+ * // app/api/users/route.ts
26
+ * import { NextRequest } from 'next/server';
27
+ * import { withSecureNow } from 'securenow/nextjs-wrapper';
28
+ *
29
+ * async function handler(request: NextRequest) {
30
+ * const body = await request.json();
31
+ * // Your logic here
32
+ * return Response.json({ success: true });
33
+ * }
34
+ *
35
+ * export const POST = withSecureNow(handler);
36
+ * ```
37
+ *
38
+ * @example
39
+ * ```typescript
40
+ * // With TypeScript types
41
+ * import { NextRequest } from 'next/server';
42
+ * import { withSecureNow } from 'securenow/nextjs-wrapper';
43
+ *
44
+ * interface CreateUserBody {
45
+ * email: string;
46
+ * name: string;
47
+ * }
48
+ *
49
+ * async function createUser(request: NextRequest) {
50
+ * const body: CreateUserBody = await request.json();
51
+ * // Body is automatically captured and redacted in traces
52
+ * return Response.json({ id: 123 });
53
+ * }
54
+ *
55
+ * export const POST = withSecureNow(createUser);
56
+ * ```
57
+ */
58
+ export function withSecureNow<T extends NextApiHandler>(
59
+ handler: T
60
+ ): T;
61
+
62
+ /**
63
+ * Configuration options for the wrapper
64
+ */
65
+ export interface WrapperOptions {
66
+ /**
67
+ * Maximum body size to capture in bytes
68
+ * @default 10240 (10KB)
69
+ */
70
+ maxBodySize?: number;
71
+
72
+ /**
73
+ * Additional sensitive field names to redact
74
+ * @default []
75
+ */
76
+ sensitiveFields?: string[];
77
+
78
+ /**
79
+ * Enable body capture
80
+ * @default true
81
+ */
82
+ enabled?: boolean;
83
+ }
84
+
85
+ /**
86
+ * Wrap a Next.js API route handler with custom options
87
+ *
88
+ * @param handler - Your API route handler function
89
+ * @param options - Configuration options
90
+ * @returns Wrapped handler with body capture enabled
91
+ */
92
+ export function withSecureNowOptions<T extends NextApiHandler>(
93
+ handler: T,
94
+ options: WrapperOptions
95
+ ): T;
package/nextjs-wrapper.js CHANGED
@@ -153,3 +153,6 @@ module.exports = {
153
153
  DEFAULT_SENSITIVE_FIELDS,
154
154
  };
155
155
 
156
+
157
+
158
+
package/nextjs.d.ts ADDED
@@ -0,0 +1,87 @@
1
+ /**
2
+ * SecureNow Next.js Integration TypeScript Declarations
3
+ */
4
+
5
+ export interface RegisterOptions {
6
+ /**
7
+ * Service name for OpenTelemetry traces
8
+ * @default process.env.SECURENOW_APPID || process.env.OTEL_SERVICE_NAME
9
+ */
10
+ serviceName?: string;
11
+
12
+ /**
13
+ * OTLP endpoint for traces
14
+ * @default process.env.SECURENOW_INSTANCE || 'http://46.62.173.237:4318'
15
+ */
16
+ endpoint?: string;
17
+
18
+ /**
19
+ * Don't append UUID to service name
20
+ * @default false
21
+ */
22
+ noUuid?: boolean;
23
+
24
+ /**
25
+ * Enable request body capture (Next.js middleware required)
26
+ * @default false
27
+ */
28
+ captureBody?: boolean;
29
+ }
30
+
31
+ /**
32
+ * Register SecureNow OpenTelemetry instrumentation for Next.js
33
+ *
34
+ * @param options - Optional configuration options
35
+ *
36
+ * @example
37
+ * ```typescript
38
+ * // instrumentation.ts
39
+ * import { registerSecureNow } from 'securenow/nextjs';
40
+ *
41
+ * export function register() {
42
+ * registerSecureNow();
43
+ * }
44
+ * ```
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * // With custom options
49
+ * import { registerSecureNow } from 'securenow/nextjs';
50
+ *
51
+ * export function register() {
52
+ * registerSecureNow({
53
+ * serviceName: 'my-nextjs-app',
54
+ * endpoint: 'http://signoz.company.com:4318',
55
+ * noUuid: true,
56
+ * });
57
+ * }
58
+ * ```
59
+ */
60
+ export function registerSecureNow(options?: RegisterOptions): void;
61
+
62
+ /**
63
+ * Default sensitive fields that are automatically redacted from traces
64
+ */
65
+ export const DEFAULT_SENSITIVE_FIELDS: readonly string[];
66
+
67
+ /**
68
+ * Redact sensitive fields from an object
69
+ * @param obj - Object to redact
70
+ * @param sensitiveFields - Array of field names to redact (case-insensitive substring match)
71
+ * @returns Redacted copy of the object
72
+ */
73
+ export function redactSensitiveData<T = any>(
74
+ obj: T,
75
+ sensitiveFields?: string[]
76
+ ): T;
77
+
78
+ /**
79
+ * Redact sensitive data from GraphQL query strings
80
+ * @param query - GraphQL query string
81
+ * @param sensitiveFields - Array of field names to redact
82
+ * @returns Redacted query string
83
+ */
84
+ export function redactGraphQLQuery(
85
+ query: string,
86
+ sensitiveFields?: string[]
87
+ ): string;