@sebspark/otel 0.2.0 → 0.2.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/dist/index.js +8 -3
- package/dist/index.mjs +8 -3
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -620,19 +620,24 @@ var getResource = async () => {
|
|
|
620
620
|
|
|
621
621
|
// src/otel.ts
|
|
622
622
|
import_api3.diag.setLogger(new import_api3.DiagConsoleLogger(), import_api3.DiagLogLevel.ERROR);
|
|
623
|
+
var isInitialized = false;
|
|
623
624
|
async function initialize() {
|
|
625
|
+
if (isInitialized) {
|
|
626
|
+
return;
|
|
627
|
+
}
|
|
628
|
+
isInitialized = true;
|
|
624
629
|
try {
|
|
625
630
|
const serviceName = process.env.OTEL_SERVICE_NAME ?? "unknown-service";
|
|
626
631
|
const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
627
632
|
const resource = await getResource();
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
);
|
|
633
|
+
const contextManager = new import_context_async_hooks.AsyncLocalStorageContextManager().enable();
|
|
634
|
+
import_api3.context.setGlobalContextManager(contextManager);
|
|
631
635
|
const logProvider = getLogProvider(resource, otlpEndpoint);
|
|
632
636
|
import_api_logs.logs.setGlobalLoggerProvider(logProvider);
|
|
633
637
|
const spanProcessor = getSpanProcessor(otlpEndpoint);
|
|
634
638
|
const metricReader = getMetricReader(otlpEndpoint);
|
|
635
639
|
const sdk = new import_sdk_node.NodeSDK({
|
|
640
|
+
contextManager,
|
|
636
641
|
spanProcessor,
|
|
637
642
|
metricReader,
|
|
638
643
|
instrumentations: [(0, import_auto_instrumentations_node.getNodeAutoInstrumentations)()],
|
package/dist/index.mjs
CHANGED
|
@@ -602,19 +602,24 @@ var getResource = async () => {
|
|
|
602
602
|
|
|
603
603
|
// src/otel.ts
|
|
604
604
|
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.ERROR);
|
|
605
|
+
var isInitialized = false;
|
|
605
606
|
async function initialize() {
|
|
607
|
+
if (isInitialized) {
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
isInitialized = true;
|
|
606
611
|
try {
|
|
607
612
|
const serviceName = process.env.OTEL_SERVICE_NAME ?? "unknown-service";
|
|
608
613
|
const otlpEndpoint = process.env.OTEL_EXPORTER_OTLP_ENDPOINT;
|
|
609
614
|
const resource = await getResource();
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
);
|
|
615
|
+
const contextManager = new AsyncLocalStorageContextManager().enable();
|
|
616
|
+
context.setGlobalContextManager(contextManager);
|
|
613
617
|
const logProvider = getLogProvider(resource, otlpEndpoint);
|
|
614
618
|
logs.setGlobalLoggerProvider(logProvider);
|
|
615
619
|
const spanProcessor = getSpanProcessor(otlpEndpoint);
|
|
616
620
|
const metricReader = getMetricReader(otlpEndpoint);
|
|
617
621
|
const sdk = new NodeSDK({
|
|
622
|
+
contextManager,
|
|
618
623
|
spanProcessor,
|
|
619
624
|
metricReader,
|
|
620
625
|
instrumentations: [getNodeAutoInstrumentations()],
|