securenow 3.0.3 → 3.0.4
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/package.json +1 -1
- package/tracing.js +11 -11
package/package.json
CHANGED
package/tracing.js
CHANGED
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
*/
|
|
18
18
|
|
|
19
19
|
const { diag, DiagConsoleLogger, DiagLogLevel } = require('@opentelemetry/api');
|
|
20
|
+
const env = k => process.env[k] ?? process.env[k.toUpperCase()] ?? process.env[k.toLowerCase()];
|
|
20
21
|
|
|
21
22
|
// ---------- Diagnostics level ----------
|
|
22
23
|
(() => {
|
|
23
|
-
const L = (
|
|
24
|
+
const L = (env('OTEL_LOG_LEVEL') || '').toLowerCase();
|
|
24
25
|
const level =
|
|
25
26
|
L === 'debug' ? DiagLogLevel.DEBUG :
|
|
26
27
|
L === 'info' ? DiagLogLevel.INFO :
|
|
@@ -48,8 +49,8 @@ try {
|
|
|
48
49
|
}
|
|
49
50
|
|
|
50
51
|
// ---------- Endpoint config (HTTP/4318) ----------
|
|
51
|
-
const endpointBase = (
|
|
52
|
-
const tracesUrl = (
|
|
52
|
+
const endpointBase = (env('SECURENOW_INSTANCE') || env('OTEL_EXPORTER_OTLP_ENDPOINT') || 'http://46.62.173.237:4318').replace(/\/$/, '');
|
|
53
|
+
const tracesUrl = (env('OTEL_EXPORTER_OTLP_TRACES_ENDPOINT') || `${endpointBase}/v1/traces`);
|
|
53
54
|
|
|
54
55
|
// ---------- Headers parsing ----------
|
|
55
56
|
function parseOtelHeaders(str) {
|
|
@@ -67,19 +68,18 @@ function parseOtelHeaders(str) {
|
|
|
67
68
|
}
|
|
68
69
|
return headers;
|
|
69
70
|
}
|
|
70
|
-
const headers = parseOtelHeaders(
|
|
71
|
-
|
|
71
|
+
const headers = parseOtelHeaders(env('OTEL_EXPORTER_OTLP_HEADERS'));
|
|
72
72
|
// ---------- Service name with UUID rules ----------
|
|
73
73
|
let serviceName;
|
|
74
|
-
if (
|
|
75
|
-
serviceName =
|
|
74
|
+
if (env('SECURENOW_APPID')) {
|
|
75
|
+
serviceName = env('SECURENOW_APPID');
|
|
76
76
|
} else {
|
|
77
77
|
// default can also be unique to avoid collisions
|
|
78
78
|
serviceName = `securenow-free-${uuidv4()}`;
|
|
79
79
|
}
|
|
80
80
|
|
|
81
81
|
// ---------- Disable instrumentations via env ----------
|
|
82
|
-
const disabledList = (
|
|
82
|
+
const disabledList = (env('SECURENOW_DISABLE_INSTRUMENTATIONS') || '')
|
|
83
83
|
.split(',')
|
|
84
84
|
.map(s => s.trim())
|
|
85
85
|
.filter(Boolean);
|
|
@@ -97,8 +97,8 @@ const sdk = new NodeSDK({
|
|
|
97
97
|
}),
|
|
98
98
|
resource: new Resource({
|
|
99
99
|
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
100
|
-
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]:
|
|
101
|
-
[SemanticResourceAttributes.SERVICE_VERSION]:
|
|
100
|
+
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env('NODE_ENV') || 'development',
|
|
101
|
+
[SemanticResourceAttributes.SERVICE_VERSION]: env('npm_package_version') || undefined,
|
|
102
102
|
}),
|
|
103
103
|
});
|
|
104
104
|
|
|
@@ -110,7 +110,7 @@ const sdk = new NodeSDK({
|
|
|
110
110
|
console.log('[securenow] OTel SDK started →', tracesUrl);
|
|
111
111
|
|
|
112
112
|
// Optional smoke test to verify export path
|
|
113
|
-
if ((
|
|
113
|
+
if ((env('SECURENOW_TEST_SPAN') || '') === '1') {
|
|
114
114
|
const api = require('@opentelemetry/api');
|
|
115
115
|
const tracer = api.trace.getTracer('securenow-smoke');
|
|
116
116
|
const span = tracer.startSpan('securenow.startup.smoke');
|