@saidsef/tracing-node 1.8.26 → 1.8.28
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/deployment/base/job.yml +1 -1
- package/libs/index.js +8 -3
- package/libs/index.test.js +44 -0
- package/package.json +7 -6
package/deployment/base/job.yml
CHANGED
package/libs/index.js
CHANGED
|
@@ -33,7 +33,14 @@ const { B3Propagator, B3InjectEncoding } = require('@opentelemetry/propagator-b3
|
|
|
33
33
|
|
|
34
34
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
|
35
35
|
|
|
36
|
-
|
|
36
|
+
/**
|
|
37
|
+
* Sets up tracing for the application with OpenTelemetry.
|
|
38
|
+
* @param {string} serviceName - The name of the service to trace.
|
|
39
|
+
* @param {string} [appName="application"] - The name of the application.
|
|
40
|
+
* @param {string|null} [endpoint=null] - The endpoint for the tracing collector.
|
|
41
|
+
* @returns {NodeTracerProvider} - The NodeTracerProvider instance for the service.
|
|
42
|
+
*/
|
|
43
|
+
module.exports.setupTracing = (serviceName, appName="application", endpoint=null) => {
|
|
37
44
|
const provider = new NodeTracerProvider({
|
|
38
45
|
resource: new Resource({
|
|
39
46
|
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
@@ -92,5 +99,3 @@ function setupTracing(serviceName, appName="application", endpoint=null) {
|
|
|
92
99
|
// Return the tracer for the service
|
|
93
100
|
return provider.getTracer(serviceName);
|
|
94
101
|
}
|
|
95
|
-
|
|
96
|
-
module.exports.setupTracing = setupTracing;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
const assert = require('assert');
|
|
2
|
+
const sinon = require('sinon');
|
|
3
|
+
|
|
4
|
+
// Mocking OpenTelemetry and its dependencies
|
|
5
|
+
const { NodeTracerProvider } = require('@opentelemetry/sdk-trace-node');
|
|
6
|
+
const { CompositePropagator, W3CBaggagePropagator, W3CTraceContextPropagator } = require('@opentelemetry/core');
|
|
7
|
+
|
|
8
|
+
const { setupTracing } = require('./index');
|
|
9
|
+
|
|
10
|
+
// Mocking OpenTelemetry and its dependencies
|
|
11
|
+
sinon.stub(NodeTracerProvider.prototype, 'addSpanProcessor');
|
|
12
|
+
sinon.stub(NodeTracerProvider.prototype, 'register');
|
|
13
|
+
sinon.stub(CompositePropagator.prototype, 'constructor');
|
|
14
|
+
sinon.stub(W3CBaggagePropagator.prototype, 'constructor');
|
|
15
|
+
sinon.stub(W3CTraceContextPropagator.prototype, 'constructor');
|
|
16
|
+
|
|
17
|
+
// Test case for setupTracing function
|
|
18
|
+
function testSetupTracing() {
|
|
19
|
+
const serviceName = 'test-service';
|
|
20
|
+
const tracer = setupTracing(serviceName);
|
|
21
|
+
|
|
22
|
+
// Ensure that setupTracing returns a valid tracer
|
|
23
|
+
assert(tracer, 'Tracer should exist');
|
|
24
|
+
|
|
25
|
+
console.log('Setup Tracing test passed successfully');
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Test case for setupTracing function with optional parameters
|
|
29
|
+
function testSetupTracingWithOptionalParams() {
|
|
30
|
+
const serviceName = 'test-service';
|
|
31
|
+
const appName = 'test-app';
|
|
32
|
+
const endpoint = 'https://your-collector-endpoint'; // Provide your collector endpoint here
|
|
33
|
+
|
|
34
|
+
const tracer = setupTracing(serviceName, appName, endpoint);
|
|
35
|
+
|
|
36
|
+
// Ensure that setupTracing with optional parameters returns a valid tracer
|
|
37
|
+
assert(tracer, 'Tracer should exist');
|
|
38
|
+
|
|
39
|
+
console.log('Setup Tracing with optional params test passed successfully');
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Run the tests
|
|
43
|
+
testSetupTracing();
|
|
44
|
+
testSetupTracingWithOptionalParams();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saidsef/tracing-node",
|
|
3
|
-
"version": "1.8.
|
|
3
|
+
"version": "1.8.28",
|
|
4
4
|
"description": "tracing NodeJS - This is a wrapper for OpenTelemetry instrumentation packages",
|
|
5
5
|
"main": "libs/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -35,11 +35,11 @@
|
|
|
35
35
|
"homepage": "https://github.com/saidsef/tracing-nodejs#readme",
|
|
36
36
|
"dependencies": {
|
|
37
37
|
"@opentelemetry/api": "^1.7.0",
|
|
38
|
-
"@opentelemetry/exporter-trace-otlp-grpc": "^0.
|
|
38
|
+
"@opentelemetry/exporter-trace-otlp-grpc": "^0.48.0",
|
|
39
39
|
"@opentelemetry/instrumentation": "^0.48.0",
|
|
40
|
-
"@opentelemetry/instrumentation-aws-sdk": "^0.
|
|
41
|
-
"@opentelemetry/instrumentation-dns": "^0.
|
|
42
|
-
"@opentelemetry/instrumentation-express": "^0.
|
|
40
|
+
"@opentelemetry/instrumentation-aws-sdk": "^0.38.0",
|
|
41
|
+
"@opentelemetry/instrumentation-dns": "^0.33.0",
|
|
42
|
+
"@opentelemetry/instrumentation-express": "^0.35.0",
|
|
43
43
|
"@opentelemetry/instrumentation-http": "^0.48.0",
|
|
44
44
|
"@opentelemetry/instrumentation-pino": "^0.35.0",
|
|
45
45
|
"@opentelemetry/propagator-b3": "^1.17.0",
|
|
@@ -49,6 +49,7 @@
|
|
|
49
49
|
"@opentelemetry/semantic-conventions": "^1.21.0"
|
|
50
50
|
},
|
|
51
51
|
"devDependencies": {
|
|
52
|
-
"eslint": "8.56.0"
|
|
52
|
+
"eslint": "8.56.0",
|
|
53
|
+
"sinon": "^17.0.1"
|
|
53
54
|
}
|
|
54
55
|
}
|