@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.
Files changed (3) hide show
  1. package/README.md +17 -3
  2. package/libs/index.mjs +25 -11
  3. 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', 'application_name', 'endpoint');
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', 'application_name', 'endpoint');
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
- | application_name | string | service / application name |
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.serviceName=process.env.HOSTNAME] - The name of the service.
45
- * @param {string} [options.appName=process.env.APP_NAME] - The name of the application.
46
- * @param {string} [options.endpoint=process.env.ENDPOINT] - The endpoint for the trace exporter.
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
- serviceName = process.env.HOSTNAME,
53
- appName = process.env.APP_NAME,
54
- endpoint = process.env.ENDPOINT
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]: appName,
61
- [SemanticResourceAttributes.CONTAINER_NAME]: serviceName,
62
- [SemanticResourceAttributes.HOST_NAME]: serviceName,
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
- serviceName: serviceName,
70
- url: endpoint,
82
+ concurrencyLimit: concurrencyLimit,
83
+ url: url,
84
+ timeoutMillis: 1000,
71
85
  };
72
86
 
73
87
  // Register the span processor with the tracer provider
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saidsef/tracing-node",
3
- "version": "2.0.0",
3
+ "version": "2.1.1",
4
4
  "description": "tracing NodeJS - This is a wrapper for OpenTelemetry instrumentation packages",
5
5
  "main": "libs/index.mjs",
6
6
  "scripts": {