@saidsef/tracing-node 1.11.0 → 2.1.0
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.mjs +37 -25
- package/package.json +1 -1
package/deployment/base/job.yml
CHANGED
package/libs/index.mjs
CHANGED
|
@@ -34,42 +34,54 @@ import {B3Propagator, B3InjectEncoding} from '@opentelemetry/propagator-b3';
|
|
|
34
34
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.INFO);
|
|
35
35
|
|
|
36
36
|
/**
|
|
37
|
-
* Sets up tracing for
|
|
38
|
-
* This function configures a NodeTracerProvider with specific resource attributes, including
|
|
39
|
-
* service name, namespace, and host. It also configures an exporter using the OTLP protocol
|
|
40
|
-
* over gRPC, with the option to specify an endpoint. Instrumentations for HTTP, Express,
|
|
41
|
-
* AWS, Pino, and DNS are registered to capture relevant spans. The function finally returns
|
|
42
|
-
* a tracer specific to the service for initiating and exporting spans.
|
|
37
|
+
* Sets up tracing for the application using OpenTelemetry.
|
|
43
38
|
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
* @param {string
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* @
|
|
55
|
-
*
|
|
56
|
-
* the
|
|
39
|
+
* This function configures a NodeTracerProvider with various instrumentations
|
|
40
|
+
* and span processors to enable tracing for the application. It supports
|
|
41
|
+
* tracing for HTTP, Express, AWS, Pino, and DNS.
|
|
42
|
+
*
|
|
43
|
+
* @param {Object} options - Configuration options for tracing.
|
|
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.
|
|
52
|
+
*
|
|
53
|
+
* @returns {Tracer} - The tracer for the service.
|
|
57
54
|
*/
|
|
58
|
-
export function setupTracing (
|
|
55
|
+
export function setupTracing (options={}) {
|
|
56
|
+
const {
|
|
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,
|
|
65
|
+
} = options;
|
|
66
|
+
|
|
59
67
|
const provider = new NodeTracerProvider({
|
|
60
68
|
resource: new Resource({
|
|
69
|
+
[SemanticResourceAttributes.CONTAINER_NAME]: containerName,
|
|
70
|
+
[SemanticResourceAttributes.DEPLOYMENT_ENVIRONMENT]: deploymentEnvironment,
|
|
71
|
+
[SemanticResourceAttributes.HOSTNAME]: hostname,
|
|
61
72
|
[SemanticResourceAttributes.SERVICE_NAME]: serviceName,
|
|
62
|
-
[SemanticResourceAttributes.SERVICE_NAMESPACE]:
|
|
63
|
-
[SemanticResourceAttributes.
|
|
64
|
-
[SemanticResourceAttributes.
|
|
73
|
+
[SemanticResourceAttributes.SERVICE_NAMESPACE]: serviceNameSpace,
|
|
74
|
+
[SemanticResourceAttributes.SERVICE_VERSION]: serviceVersion || '0.0.0',
|
|
75
|
+
[SemanticResourceAttributes.URL]: url,
|
|
65
76
|
instrumentationLibrarySemanticConvention: true,
|
|
66
77
|
}),
|
|
67
78
|
});
|
|
68
79
|
|
|
69
80
|
// Configure exporter with the Collector endpoint - uses gRPC
|
|
70
81
|
const exportOptions = {
|
|
71
|
-
|
|
72
|
-
url:
|
|
82
|
+
concurrencyLimit: concurrencyLimit,
|
|
83
|
+
url: url,
|
|
84
|
+
timeoutMillis: 1000,
|
|
73
85
|
};
|
|
74
86
|
|
|
75
87
|
// Register the span processor with the tracer provider
|