@saidsef/tracing-node 2.0.0 → 2.1.1
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/README.md +17 -3
- package/libs/index.mjs +25 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -22,14 +22,28 @@ npm install @saidsef/tracing-node --save
|
|
|
22
22
|
|
|
23
23
|
## Usage
|
|
24
24
|
|
|
25
|
+
You can set required params via env variables or function:
|
|
26
|
+
|
|
27
|
+
Env vars:
|
|
28
|
+
```
|
|
29
|
+
CONTAINER_NAME
|
|
30
|
+
NODE_ENV
|
|
31
|
+
HOSTNAME
|
|
32
|
+
SERVICE_NAME
|
|
33
|
+
NAME_SPACE
|
|
34
|
+
SERVICE_VERSION
|
|
35
|
+
ENDPOINT
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
Function args
|
|
25
39
|
```
|
|
26
40
|
const { setupTracing } = require('@saidsef/tracing-node');
|
|
27
|
-
setupTracing('hostname', '
|
|
41
|
+
setupTracing({hostname: 'hostname', serviceName: 'service_name', endpoint: 'endpoint'});
|
|
28
42
|
```
|
|
29
43
|
|
|
30
44
|
```
|
|
31
45
|
import { setupTracing } from '@saidsef/tracing-node';
|
|
32
|
-
setupTracing('hostname', '
|
|
46
|
+
setupTracing({hostname: 'hostname', serviceName: 'service_name', endpoint: 'endpoint'});
|
|
33
47
|
```
|
|
34
48
|
|
|
35
49
|
### Required Parameters are
|
|
@@ -37,7 +51,7 @@ setupTracing('hostname', 'application_name', 'endpoint');
|
|
|
37
51
|
| Name | Type | Description|
|
|
38
52
|
|----- | ---- | ------------- |
|
|
39
53
|
| hostname | string | container / pod hostname |
|
|
40
|
-
|
|
|
54
|
+
| service_name | string | service / application name |
|
|
41
55
|
| endpoint | string | tracing endpoint i.e. `<schema>://<host>:<port>` |
|
|
42
56
|
|
|
43
57
|
## Source
|
package/libs/index.mjs
CHANGED
|
@@ -41,33 +41,47 @@ diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
|
|
41
41
|
* tracing for HTTP, Express, AWS, Pino, and DNS.
|
|
42
42
|
*
|
|
43
43
|
* @param {Object} options - Configuration options for tracing.
|
|
44
|
-
* @param {string} [options.
|
|
45
|
-
* @param {string} [options.
|
|
46
|
-
* @param {string} [options.
|
|
44
|
+
* @param {string} [options.containerName=process.env.CONTAINER_NAME] - The name of the container.
|
|
45
|
+
* @param {string} [options.deploymentEnvironment=process.env.NODE_ENV] - The deployment environment.
|
|
46
|
+
* @param {string} [options.hostname=process.env.HOSTNAME] - The hostname of the service.
|
|
47
|
+
* @param {string} [options.serviceName=process.env.SERVICE_NAME] - The name of the service.
|
|
48
|
+
* @param {string} [options.serviceNameSpace=process.env.NAME_SPACE || 'default'] - The namespace of the service.
|
|
49
|
+
* @param {string} [options.serviceVersion=process.env.SERVICE_VERSION || '0.0.0'] - The version of the service.
|
|
50
|
+
* @param {string} [options.url=process.env.ENDPOINT] - The endpoint URL for the tracing collector.
|
|
51
|
+
* @param {number} [options.concurrencyLimit=10] - The concurrency limit for the exporter.
|
|
47
52
|
*
|
|
48
53
|
* @returns {Tracer} - The tracer for the service.
|
|
49
54
|
*/
|
|
50
55
|
export function setupTracing (options={}) {
|
|
51
56
|
const {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
57
|
+
containerName = process.env.CONTAINER_NAME,
|
|
58
|
+
deploymentEnvironment = process.env.NODE_ENV,
|
|
59
|
+
hostname = process.env.HOSTNAME,
|
|
60
|
+
serviceName = process.env.SERVICE_NAME,
|
|
61
|
+
serviceNameSpace = process.env.NAME_SPACE || 'default',
|
|
62
|
+
serviceVersion = process.env.SERVICE_VERSION || '0.0.0',
|
|
63
|
+
url = process.env.ENDPOINT,
|
|
64
|
+
concurrencyLimit = 10,
|
|
55
65
|
} = options;
|
|
56
66
|
|
|
57
67
|
const provider = new NodeTracerProvider({
|
|
58
68
|
resource: new Resource({
|
|
69
|
+
[SemanticResourceAttributes.CONTAINER_NAME]: containerName || serviceName,
|
|
70
|
+
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: deploymentEnvironment,
|
|
71
|
+
[SemanticResourceAttributes.HOSTNAME]: hostname,
|
|
59
72
|
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
60
|
-
[SemanticResourceAttributes.SERVICE_NAMESPACE]:
|
|
61
|
-
[SemanticResourceAttributes.
|
|
62
|
-
[SemanticResourceAttributes.
|
|
73
|
+
[SemanticResourceAttributes.SERVICE_NAMESPACE]: serviceNameSpace,
|
|
74
|
+
[SemanticResourceAttributes.SERVICE_VERSION]: serviceVersion || '0.0.0',
|
|
75
|
+
[SemanticResourceAttributes.URL]: url,
|
|
63
76
|
instrumentationLibrarySemanticConvention: true,
|
|
64
77
|
}),
|
|
65
78
|
});
|
|
66
79
|
|
|
67
80
|
// Configure exporter with the Collector endpoint - uses gRPC
|
|
68
81
|
const exportOptions = {
|
|
69
|
-
|
|
70
|
-
url:
|
|
82
|
+
concurrencyLimit: concurrencyLimit,
|
|
83
|
+
url: url,
|
|
84
|
+
timeoutMillis: 1000,
|
|
71
85
|
};
|
|
72
86
|
|
|
73
87
|
// Register the span processor with the tracer provider
|