securenow 5.6.0 → 5.7.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.
@@ -1,239 +1,234 @@
1
- # SecureNow Logging - Quick Start
2
-
3
- Get logging set up in your Node.js app in under 2 minutes!
4
-
5
- ---
6
-
7
- ## 1. Install
8
-
9
- ```bash
10
- npm install securenow
11
- ```
12
-
13
- ---
14
-
15
- ## 2. Configure Environment
16
-
17
- Create `.env` file or export variables:
18
-
19
- ```bash
20
- SECURENOW_LOGGING_ENABLED=1
21
- SECURENOW_APPID=my-app
22
- SECURENOW_INSTANCE=http://your-otlp-backend:4318
23
-
24
- # For SecureNow / hosted OTLP (example):
25
- # SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
26
- # OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<your-key>"
27
- ```
28
-
29
- ---
30
-
31
- ## 3. Add to Your App
32
-
33
- **Option A: Automatic Console Logging (Easiest)**
34
-
35
- Add these two lines at the top of your main file:
36
-
37
- ```javascript
38
- // app.js, index.js, server.js, or main.ts
39
- require('securenow/register');
40
- require('securenow/console-instrumentation');
41
-
42
- // That's it! Now use console normally
43
- console.log('App started');
44
- console.error('An error occurred', { userId: 123 });
45
- ```
46
-
47
- **Option B: Use NODE_OPTIONS (No code changes)**
48
-
49
- ```bash
50
- NODE_OPTIONS="-r securenow/register -r securenow/console-instrumentation" node app.js
51
- ```
52
-
53
- ---
54
-
55
- ## 4. Run Your App
56
-
57
- ```bash
58
- node app.js
59
- # or
60
- npm start
61
- ```
62
-
63
- You should see:
64
-
65
- ```
66
- [securenow] OTel SDK started → http://your-otlp-backend:4318/v1/traces
67
- [securenow] 📋 Logging: ENABLED → http://your-otlp-backend:4318/v1/logs
68
- [securenow] Console instrumentation installed
69
- ```
70
-
71
- ---
72
-
73
- ## 5. View Logs in SecureNow
74
-
75
- 1. Open your SecureNow dashboard
76
- 2. Go to **Logs** section
77
- 3. Filter by `service.name = my-app`
78
- 4. See all your logs with automatic trace correlation!
79
-
80
- ---
81
-
82
- ## Framework-Specific Examples
83
-
84
- ### Express.js
85
-
86
- ```javascript
87
- // app.js
88
- require('securenow/register');
89
- require('securenow/console-instrumentation');
90
-
91
- const express = require('express');
92
- const app = express();
93
-
94
- app.get('/', (req, res) => {
95
- console.log('Request received');
96
- res.send('Hello World');
97
- });
98
-
99
- app.listen(3000);
100
- ```
101
-
102
- ### Next.js
103
-
104
- ```typescript
105
- // instrumentation.ts (in project root)
106
- export async function register() {
107
- if (process.env.NEXT_RUNTIME === 'nodejs') {
108
- process.env.SECURENOW_LOGGING_ENABLED = '1';
109
- await import('securenow/register');
110
- await import('securenow/console-instrumentation');
111
- }
112
- }
113
- ```
114
-
115
- ```bash
116
- # .env.local
117
- SECURENOW_LOGGING_ENABLED=1
118
- SECURENOW_APPID=my-nextjs-app
119
- SECURENOW_INSTANCE=http://localhost:4318
120
- ```
121
-
122
- ### Fastify
123
-
124
- ```javascript
125
- // server.js
126
- require('securenow/register');
127
- require('securenow/console-instrumentation');
128
-
129
- const fastify = require('fastify')();
130
-
131
- fastify.get('/', async () => {
132
- console.log('Route called');
133
- return { hello: 'world' };
134
- });
135
-
136
- fastify.listen({ port: 3000 });
137
- ```
138
-
139
- ### NestJS
140
-
141
- ```typescript
142
- // main.ts
143
- require('securenow/register');
144
- require('securenow/console-instrumentation');
145
-
146
- import { NestFactory } from '@nestjs/core';
147
- import { AppModule } from './app.module';
148
-
149
- async function bootstrap() {
150
- const app = await NestFactory.create(AppModule);
151
- console.log('App starting');
152
- await app.listen(3000);
153
- }
154
-
155
- bootstrap();
156
- ```
157
-
158
- ---
159
-
160
- ## Troubleshooting
161
-
162
- **Logs not appearing?**
163
-
164
- 1. Check `SECURENOW_LOGGING_ENABLED=1` is set
165
- 2. Verify your OTLP / SecureNow endpoint is correct
166
- 3. Enable debug: `OTEL_LOG_LEVEL=debug`
167
-
168
- **Console instrumentation not working?**
169
-
170
- Make sure require order is correct:
171
-
172
- ```javascript
173
- // ✅ Correct
174
- require('securenow/register'); // First
175
- require('securenow/console-instrumentation'); // Second
176
-
177
- // ❌ Wrong
178
- require('express');
179
- require('securenow/register'); // Too late!
180
- ```
181
-
182
- ---
183
-
184
- ## What Gets Logged?
185
-
186
- All standard console methods:
187
-
188
- - `console.log()` → INFO
189
- - `console.info()` → INFO
190
- - `console.warn()` → WARN
191
- - `console.error()` → ERROR
192
- - `console.debug()` DEBUG
193
-
194
- **Structured logging example:**
195
-
196
- ```javascript
197
- console.log('User logged in', {
198
- userId: 123,
199
- email: 'user@example.com',
200
- ip: '192.168.1.1'
201
- });
202
- ```
203
-
204
- This creates a log with attributes you can filter/search in SecureNow!
205
-
206
- ---
207
-
208
- ## Advanced Usage
209
-
210
- **Direct Logger API:**
211
-
212
- ```javascript
213
- const { getLogger } = require('securenow/tracing');
214
- const logger = getLogger('my-module', '1.0.0');
215
-
216
- logger.emit({
217
- severityNumber: 9,
218
- severityText: 'INFO',
219
- body: 'Custom log message',
220
- attributes: {
221
- customField: 'value',
222
- },
223
- });
224
- ```
225
-
226
- ---
227
-
228
- ## Next Steps
229
-
230
- - [Complete Logging Guide](./LOGGING-GUIDE.md) - All features and options
231
- - [SecureNow](https://securenow.ai/)
232
- - [Documentation](./INDEX.md)
233
- - [Combine with Tracing](../README.md) - Full observability
234
-
235
- ---
236
-
237
- **That's it!** 🎉 Your app is now sending logs to SecureNow.
238
-
239
- Need help? Check the [full documentation](./LOGGING-GUIDE.md) or open an issue.
1
+ # SecureNow Logging - Quick Start
2
+
3
+ Get logging set up in your Node.js app in under 2 minutes!
4
+
5
+ **Since v5.6.0:** When `SECURENOW_LOGGING_ENABLED=1` is set, all `console.log` / `warn` / `error` / `info` / `debug` calls are automatically forwarded as OTLP log records. You only need `require('securenow/register')`—a separate `console-instrumentation` preload is no longer required.
6
+
7
+ ---
8
+
9
+ ## 1. Install
10
+
11
+ ```bash
12
+ npm install securenow
13
+ ```
14
+
15
+ ---
16
+
17
+ ## 2. Configure Environment
18
+
19
+ Create `.env` file or export variables:
20
+
21
+ ```bash
22
+ SECURENOW_LOGGING_ENABLED=1
23
+ SECURENOW_APPID=my-app
24
+ SECURENOW_INSTANCE=http://your-otlp-backend:4318
25
+
26
+ # For SecureNow / hosted OTLP (example):
27
+ # SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
28
+ # OTEL_EXPORTER_OTLP_HEADERS="x-api-key=<your-key>"
29
+ ```
30
+
31
+ ---
32
+
33
+ ## 3. Add to Your App
34
+
35
+ **Option A: Automatic Console Logging (Easiest)**
36
+
37
+ Add this line at the top of your main file:
38
+
39
+ ```javascript
40
+ // app.js, index.js, server.js, or main.ts
41
+ require('securenow/register');
42
+
43
+ // That's it! Now use console normally
44
+ console.log('App started');
45
+ console.error('An error occurred', { userId: 123 });
46
+ ```
47
+
48
+ **Option B: Use NODE_OPTIONS (No code changes)**
49
+
50
+ ```bash
51
+ NODE_OPTIONS="-r securenow/register" node app.js
52
+ ```
53
+
54
+ ---
55
+
56
+ ## 4. Run Your App
57
+
58
+ ```bash
59
+ node app.js
60
+ # or
61
+ npm start
62
+ ```
63
+
64
+ You should see:
65
+
66
+ ```
67
+ [securenow] OTel SDK started → http://your-otlp-backend:4318/v1/traces
68
+ [securenow] 📋 Logging: ENABLED → http://your-otlp-backend:4318/v1/logs
69
+ ```
70
+
71
+ ---
72
+
73
+ ## 5. View Logs in SecureNow
74
+
75
+ 1. Open your SecureNow dashboard
76
+ 2. Go to **Logs** section
77
+ 3. Filter by `service.name = my-app`
78
+ 4. See all your logs with automatic trace correlation!
79
+
80
+ ---
81
+
82
+ ## Framework-Specific Examples
83
+
84
+ ### Express.js
85
+
86
+ ```javascript
87
+ // app.js
88
+ require('securenow/register');
89
+
90
+ const express = require('express');
91
+ const app = express();
92
+
93
+ app.get('/', (req, res) => {
94
+ console.log('Request received');
95
+ res.send('Hello World');
96
+ });
97
+
98
+ app.listen(3000);
99
+ ```
100
+
101
+ ### Next.js
102
+
103
+ ```typescript
104
+ // instrumentation.ts (in project root)
105
+ export async function register() {
106
+ if (process.env.NEXT_RUNTIME === 'nodejs') {
107
+ process.env.SECURENOW_LOGGING_ENABLED = '1';
108
+ await import('securenow/register');
109
+ }
110
+ }
111
+ ```
112
+
113
+ ```bash
114
+ # .env.local
115
+ SECURENOW_LOGGING_ENABLED=1
116
+ SECURENOW_APPID=my-nextjs-app
117
+ SECURENOW_INSTANCE=http://localhost:4318
118
+ ```
119
+
120
+ ### Fastify
121
+
122
+ ```javascript
123
+ // server.js
124
+ require('securenow/register');
125
+
126
+ const fastify = require('fastify')();
127
+
128
+ fastify.get('/', async () => {
129
+ console.log('Route called');
130
+ return { hello: 'world' };
131
+ });
132
+
133
+ fastify.listen({ port: 3000 });
134
+ ```
135
+
136
+ ### NestJS
137
+
138
+ ```typescript
139
+ // main.ts
140
+ require('securenow/register');
141
+
142
+ import { NestFactory } from '@nestjs/core';
143
+ import { AppModule } from './app.module';
144
+
145
+ async function bootstrap() {
146
+ const app = await NestFactory.create(AppModule);
147
+ console.log('App starting');
148
+ await app.listen(3000);
149
+ }
150
+
151
+ bootstrap();
152
+ ```
153
+
154
+ ---
155
+
156
+ ## Troubleshooting
157
+
158
+ **Logs not appearing?**
159
+
160
+ 1. Check `SECURENOW_LOGGING_ENABLED=1` is set
161
+ 2. Verify your OTLP / SecureNow endpoint is correct
162
+ 3. Enable debug: `OTEL_LOG_LEVEL=debug`
163
+
164
+ **Console logs not forwarding?**
165
+
166
+ Load `securenow/register` before other app code so logging hooks run first:
167
+
168
+ ```javascript
169
+ // ✅ Correct
170
+ require('securenow/register'); // First
171
+
172
+ // ❌ Wrong
173
+ require('express');
174
+ require('securenow/register'); // Too late!
175
+ ```
176
+
177
+ ---
178
+
179
+ ## What Gets Logged?
180
+
181
+ All standard console methods:
182
+
183
+ - `console.log()` → INFO
184
+ - `console.info()` INFO
185
+ - `console.warn()` → WARN
186
+ - `console.error()` → ERROR
187
+ - `console.debug()` → DEBUG
188
+
189
+ **Structured logging example:**
190
+
191
+ ```javascript
192
+ console.log('User logged in', {
193
+ userId: 123,
194
+ email: 'user@example.com',
195
+ ip: '192.168.1.1'
196
+ });
197
+ ```
198
+
199
+ This creates a log with attributes you can filter/search in SecureNow!
200
+
201
+ ---
202
+
203
+ ## Advanced Usage
204
+
205
+ **Direct Logger API:**
206
+
207
+ ```javascript
208
+ const { getLogger } = require('securenow/tracing');
209
+ const logger = getLogger('my-module', '1.0.0');
210
+
211
+ logger.emit({
212
+ severityNumber: 9,
213
+ severityText: 'INFO',
214
+ body: 'Custom log message',
215
+ attributes: {
216
+ customField: 'value',
217
+ },
218
+ });
219
+ ```
220
+
221
+ ---
222
+
223
+ ## Next Steps
224
+
225
+ - [Complete Logging Guide](./LOGGING-GUIDE.md) - All features and options
226
+ - [SecureNow](https://securenow.ai/)
227
+ - [Documentation](./INDEX.md)
228
+ - [Combine with Tracing](../README.md) - Full observability
229
+
230
+ ---
231
+
232
+ **That's it!** 🎉 Your app is now sending logs to SecureNow.
233
+
234
+ Need help? Check the [full documentation](./LOGGING-GUIDE.md) or open an issue.
@@ -0,0 +1,166 @@
1
+ # SecureNow — Nuxt 3 Setup Guide
2
+
3
+ ## Quick Start (1 minute)
4
+
5
+ ### 1. Install
6
+
7
+ ```bash
8
+ npm install securenow
9
+ ```
10
+
11
+ ### 2. Add the module to `nuxt.config.ts`
12
+
13
+ ```ts
14
+ export default defineNuxtConfig({
15
+ modules: ['securenow/nuxt'],
16
+ });
17
+ ```
18
+
19
+ ### 3. Set environment variables
20
+
21
+ Create a `.env` file in your project root:
22
+
23
+ ```env
24
+ SECURENOW_APPID=my-nuxt-app
25
+ SECURENOW_INSTANCE=https://freetrial.securenow.ai:4318
26
+ ```
27
+
28
+ ### 4. Start your app
29
+
30
+ ```bash
31
+ nuxt dev
32
+ ```
33
+
34
+ You should see in the console:
35
+
36
+ ```
37
+ [securenow] Nuxt module loaded — server plugin registered
38
+ [securenow] 🚀 Nuxt OTel SDK started → https://freetrial.securenow.ai:4318/v1/traces
39
+ [securenow] service.name=my-nuxt-app instance.id=my-nuxt-app-...
40
+ ```
41
+
42
+ That's it — all server-side requests are now traced.
43
+
44
+ ---
45
+
46
+ ## Configuration
47
+
48
+ ### Module options in `nuxt.config.ts`
49
+
50
+ ```ts
51
+ export default defineNuxtConfig({
52
+ modules: ['securenow/nuxt'],
53
+ securenow: {
54
+ serviceName: 'my-nuxt-app', // overrides SECURENOW_APPID
55
+ endpoint: 'http://host:4318', // overrides SECURENOW_INSTANCE
56
+ noUuid: true, // single service.name (no UUID suffix)
57
+ captureBody: true, // capture POST/PUT/PATCH bodies
58
+ logging: true, // forward console.* as OTLP logs
59
+ },
60
+ });
61
+ ```
62
+
63
+ ### Environment variables
64
+
65
+ All standard SecureNow env vars are supported:
66
+
67
+ | Variable | Description | Default |
68
+ |----------|-------------|---------|
69
+ | `SECURENOW_APPID` | Service name | `nuxt-app-<uuid>` |
70
+ | `SECURENOW_INSTANCE` | OTLP base URL | `https://freetrial.securenow.ai:4318` |
71
+ | `SECURENOW_NO_UUID` | Don't append UUID to service name | `false` |
72
+ | `SECURENOW_LOGGING_ENABLED` | Forward console logs as OTLP | `false` |
73
+ | `SECURENOW_CAPTURE_BODY` | Capture request bodies | `false` |
74
+ | `SECURENOW_MAX_BODY_SIZE` | Max body size to capture (bytes) | `10240` |
75
+ | `SECURENOW_SENSITIVE_FIELDS` | Extra fields to redact (CSV) | _(built-in list)_ |
76
+ | `OTEL_EXPORTER_OTLP_ENDPOINT` | Alternative OTLP base URL | — |
77
+ | `OTEL_EXPORTER_OTLP_HEADERS` | OTLP headers (k=v,k2=v2) | — |
78
+
79
+ ---
80
+
81
+ ## What gets traced
82
+
83
+ ### Automatic (out of the box)
84
+
85
+ - All Nitro server handler requests (API routes, SSR pages, middleware)
86
+ - HTTP method, path, status code, duration
87
+ - Client IP address (with proxy-aware resolution)
88
+ - User-Agent, Referer, Origin, Host
89
+ - Security header presence (auth, cookies, CSRF)
90
+ - Request IDs and correlation headers
91
+
92
+ ### With `captureBody: true`
93
+
94
+ - POST/PUT/PATCH request bodies (JSON, form-urlencoded, GraphQL)
95
+ - Sensitive fields auto-redacted (passwords, tokens, etc.)
96
+ - Bodies larger than `SECURENOW_MAX_BODY_SIZE` are skipped
97
+
98
+ ### With `logging: true`
99
+
100
+ - All `console.log/info/warn/error/debug` calls forwarded as OTLP log records
101
+ - Logs correlated with active trace spans
102
+
103
+ ---
104
+
105
+ ## Comparison with Next.js integration
106
+
107
+ | Feature | Nuxt (`securenow/nuxt`) | Next.js (`securenow/nextjs`) |
108
+ |---------|-------------------------|------------------------------|
109
+ | Setup | Add to `modules` array | Create `instrumentation.ts` |
110
+ | Config | `nuxt.config.ts` | `.env.local` + `next.config.js` |
111
+ | Server tracing | Nitro hooks | HTTP instrumentation |
112
+ | Edge runtime | Not supported | Skipped gracefully |
113
+ | Vercel support | Via env vars | `@vercel/otel` integration |
114
+ | Body capture | HTTP instrumentation | Middleware + `Request.clone()` |
115
+ | Logging | Console patching | Console patching |
116
+
117
+ ---
118
+
119
+ ## Deployment
120
+
121
+ ### Node.js server (PM2, Docker, etc.)
122
+
123
+ Works out of the box with `nuxt build && node .output/server/index.mjs`.
124
+
125
+ ### Vercel / Netlify / Cloudflare
126
+
127
+ Set env vars in the platform dashboard:
128
+
129
+ ```
130
+ SECURENOW_APPID=my-nuxt-app
131
+ SECURENOW_INSTANCE=https://your-otlp-backend:4318
132
+ ```
133
+
134
+ > Note: On edge runtimes (Cloudflare Workers, Vercel Edge), some Node.js-specific
135
+ > instrumentations may not be available. Server-handler tracing via Nitro hooks
136
+ > still works.
137
+
138
+ ---
139
+
140
+ ## Troubleshooting
141
+
142
+ ### No traces appearing
143
+
144
+ 1. Check that `SECURENOW_APPID` and `SECURENOW_INSTANCE` are set
145
+ 2. Look for `[securenow] 🚀 Nuxt OTel SDK started` in the console
146
+ 3. Verify the OTLP endpoint is reachable from your server
147
+
148
+ ### Module not loading
149
+
150
+ Make sure you're using Nuxt 3 (`nuxt: ">=3.0.0"`) and the module is listed
151
+ in the `modules` array (not `buildModules`).
152
+
153
+ ### OpenTelemetry packages bundled by Nitro
154
+
155
+ The module automatically externalizes OTel packages. If you see bundling errors,
156
+ manually add to `nuxt.config.ts`:
157
+
158
+ ```ts
159
+ export default defineNuxtConfig({
160
+ nitro: {
161
+ externals: {
162
+ external: ['securenow', '@opentelemetry/api', '@opentelemetry/sdk-node'],
163
+ },
164
+ },
165
+ });
166
+ ```