securenow 7.0.0-anas → 7.0.0-anas.2

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/app-config.js CHANGED
@@ -6,18 +6,26 @@
6
6
  * Used by both the SDK (tracing.js, nextjs.js, nuxt-server-plugin.mjs) and
7
7
  * the CLI to answer three questions with a single source of truth:
8
8
  *
9
- * - Which app key routes this telemetry? (resolveAppKey)
10
- * - What service.name label to show? (resolveAppId)
11
- * - Which OTLP collector to hit? (resolveInstance)
9
+ * - What is the app routing key? (resolveAppKey) — used as OTel service.name
10
+ * AND as x-api-key header. The collector
11
+ * filters ClickHouse queries by
12
+ * `resource_string_service$$name IN (...)`
13
+ * so service.name MUST be the app.key UUID.
14
+ * - What human label to show? (resolveAppName) — display only, never
15
+ * sent to the collector.
16
+ * - Which OTLP collector to hit? (resolveInstance)
12
17
  *
13
18
  * Resolution order (first non-empty wins):
14
19
  *
15
20
  * 1. Explicit environment variable
16
- * (SECURENOW_API_KEY / SECURENOW_APPID / SECURENOW_INSTANCE)
21
+ * (SECURENOW_APPID / SECURENOW_API_KEY / SECURENOW_INSTANCE)
17
22
  * 2. Project-local credentials (./.securenow/credentials.json)
18
23
  * 3. Global credentials (~/.securenow/credentials.json)
19
- * 4. package.json#name (for appId only)
24
+ * 4. package.json#name (for the human label only — can't route on this)
20
25
  * 5. Hard default / null
26
+ *
27
+ * Credentials file schema:
28
+ * { token, email, expiresAt, app: { key: <uuid>, name: <display>, instance } }
21
29
  */
22
30
 
23
31
  const fs = require('fs');
@@ -72,8 +80,11 @@ function pick(value) {
72
80
  return str.length > 0 ? str : null;
73
81
  }
74
82
 
83
+ // Routing key = app.key UUID. This is what the collector filters on.
84
+ // Also used as x-api-key header once the collector supports it.
75
85
  function resolveAppKey() {
76
86
  const fromEnv =
87
+ pick(process.env.SECURENOW_APPID) ||
77
88
  pick(process.env.SECURENOW_API_KEY) ||
78
89
  pick(process.env.securenow);
79
90
  if (fromEnv) return fromEnv;
@@ -83,18 +94,24 @@ function resolveAppKey() {
83
94
  return null;
84
95
  }
85
96
 
86
- function resolveAppId() {
87
- const fromEnv =
88
- pick(process.env.OTEL_SERVICE_NAME) ||
89
- pick(process.env.SECURENOW_APPID);
97
+ // Human label for observability tools — never touches collector routing.
98
+ // Falls back to package.json#name so pre-login users still see something readable.
99
+ function resolveAppName() {
100
+ const fromEnv = pick(process.env.OTEL_SERVICE_NAME);
90
101
  if (fromEnv) return fromEnv;
91
102
 
92
103
  const creds = loadCredentials();
93
- if (creds && creds.app && pick(creds.app.id)) return pick(creds.app.id);
104
+ if (creds && creds.app && pick(creds.app.name)) return pick(creds.app.name);
94
105
 
95
106
  return loadPackageJsonName();
96
107
  }
97
108
 
109
+ // Legacy alias — callers that want "whatever identifies this process to OTel"
110
+ // get the routing key if logged in, otherwise the human label fallback.
111
+ function resolveAppId() {
112
+ return resolveAppKey() || resolveAppName();
113
+ }
114
+
98
115
  function resolveInstance() {
99
116
  const fromEnv =
100
117
  pick(process.env.SECURENOW_INSTANCE) ||
@@ -110,9 +127,13 @@ function resolveInstance() {
110
127
  }
111
128
 
112
129
  function resolveAll() {
130
+ const appKey = resolveAppKey();
113
131
  return {
114
- appKey: resolveAppKey(),
115
- appId: resolveAppId(),
132
+ appKey,
133
+ appName: resolveAppName(),
134
+ // service.name must be the routing UUID when available — that's what the
135
+ // collector filters on. Fall back to the human label pre-login.
136
+ appId: appKey || resolveAppName(),
116
137
  instance: resolveInstance(),
117
138
  };
118
139
  }
@@ -120,6 +141,7 @@ function resolveAll() {
120
141
  module.exports = {
121
142
  FREE_TRIAL_INSTANCE,
122
143
  resolveAppKey,
144
+ resolveAppName,
123
145
  resolveAppId,
124
146
  resolveInstance,
125
147
  resolveAll,
package/cli/apps.js CHANGED
@@ -310,7 +310,7 @@ async function setDefault(args) {
310
310
  }
311
311
  config.setApp({
312
312
  key: app.key,
313
- id: app.name || app.key,
313
+ name: app.name || null,
314
314
  instance: instanceUrl(inst),
315
315
  });
316
316
  ui.success(`Default application set to ${ui.c.bold(app.name || key)}`);
package/cli/auth.js CHANGED
@@ -54,7 +54,7 @@ async function loginWithBrowser() {
54
54
  const error = url.searchParams.get('error');
55
55
  const returnedState = url.searchParams.get('state');
56
56
  const appKey = url.searchParams.get('app_key');
57
- const appId = url.searchParams.get('app_id');
57
+ const appName = url.searchParams.get('app_name');
58
58
  const appInstance = url.searchParams.get('app_instance');
59
59
 
60
60
  res.writeHead(200, { 'Content-Type': 'text/html; charset=utf-8' });
@@ -75,10 +75,10 @@ async function loginWithBrowser() {
75
75
 
76
76
  if (token) {
77
77
  pendingToken = token;
78
- if (appKey || appId || appInstance) {
78
+ if (appKey || appName || appInstance) {
79
79
  pendingApp = {
80
80
  key: appKey || null,
81
- id: appId || null,
81
+ name: appName || null,
82
82
  instance: appInstance || null,
83
83
  };
84
84
  }
@@ -229,8 +229,8 @@ async function login(args, flags) {
229
229
  console.log('');
230
230
  ui.success(`Logged in as ${ui.c.bold(email)}`);
231
231
  ui.info(local ? 'Credentials saved to project .securenow/ (local)' : 'Credentials saved to ~/.securenow/ (global)');
232
- if (app && app.id) {
233
- ui.info(`Linked to app ${ui.c.bold(app.id)}${app.key ? ` (${ui.c.dim(app.key)})` : ''}`);
232
+ if (app && (app.name || app.key)) {
233
+ ui.info(`Linked to app ${ui.c.bold(app.name || app.key)}${app.key ? ` (${ui.c.dim(app.key)})` : ''}`);
234
234
  }
235
235
  if (exp) {
236
236
  const days = Math.ceil((exp - Date.now()) / (1000 * 60 * 60 * 24));
package/cli/config.js CHANGED
@@ -120,10 +120,10 @@ function getToken() {
120
120
 
121
121
  function setAuth(token, email, expiresAt, { local = false, app = null } = {}) {
122
122
  const payload = { token, email, expiresAt };
123
- if (app && (app.key || app.id || app.instance)) {
123
+ if (app && (app.key || app.name || app.instance)) {
124
124
  payload.app = {
125
125
  key: app.key || null,
126
- id: app.id || null,
126
+ name: app.name || null,
127
127
  instance: app.instance || null,
128
128
  };
129
129
  }
@@ -143,7 +143,7 @@ function setApp(app, { local } = {}) {
143
143
  ...existing,
144
144
  app: {
145
145
  key: app.key || null,
146
- id: app.id || null,
146
+ name: app.name || null,
147
147
  instance: app.instance || null,
148
148
  },
149
149
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "securenow",
3
- "version": "7.0.0-anas",
3
+ "version": "7.0.0-anas.2",
4
4
  "description": "OpenTelemetry instrumentation for Node.js, Next.js, and Nuxt - Send traces and logs to any OTLP-compatible backend",
5
5
  "type": "commonjs",
6
6
  "main": "register.js",
@@ -161,7 +161,7 @@
161
161
  "uuid": "^9.0.0"
162
162
  },
163
163
  "optionalDependencies": {
164
- "@vercel/otel": "^1.14.0"
164
+ "@vercel/otel": "1.10.4"
165
165
  },
166
166
  "overrides": {
167
167
  "@opentelemetry/api": "1.7.0",