securenow 3.0.3 → 3.0.5
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 +13 -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);
|
|
@@ -88,6 +88,7 @@ for (const name of disabledList) disabledMap[name] = { enabled: false };
|
|
|
88
88
|
|
|
89
89
|
// ---------- Build exporter & SDK ----------
|
|
90
90
|
const traceExporter = new OTLPTraceExporter({ url: tracesUrl, headers });
|
|
91
|
+
const serviceInstanceId = `${serviceName}-${uuidv4()}`;
|
|
91
92
|
|
|
92
93
|
const sdk = new NodeSDK({
|
|
93
94
|
traceExporter,
|
|
@@ -97,8 +98,9 @@ const sdk = new NodeSDK({
|
|
|
97
98
|
}),
|
|
98
99
|
resource: new Resource({
|
|
99
100
|
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
100
|
-
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]:
|
|
101
|
-
[SemanticResourceAttributes.
|
|
101
|
+
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: env('NODE_ENV') || 'development',
|
|
102
|
+
[SemanticResourceAttributes.SERVICE_INSTANCE_ID]: serviceInstanceId,
|
|
103
|
+
[SemanticResourceAttributes.SERVICE_VERSION]: env('npm_package_version') || undefined,
|
|
102
104
|
}),
|
|
103
105
|
});
|
|
104
106
|
|
|
@@ -110,7 +112,7 @@ const sdk = new NodeSDK({
|
|
|
110
112
|
console.log('[securenow] OTel SDK started →', tracesUrl);
|
|
111
113
|
|
|
112
114
|
// Optional smoke test to verify export path
|
|
113
|
-
if ((
|
|
115
|
+
if ((env('SECURENOW_TEST_SPAN') || '') === '1') {
|
|
114
116
|
const api = require('@opentelemetry/api');
|
|
115
117
|
const tracer = api.trace.getTracer('securenow-smoke');
|
|
116
118
|
const span = tracer.startSpan('securenow.startup.smoke');
|