@atrim/instrument-node 0.5.0-c05e3a1-20251119131235 → 0.5.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 +66 -0
- package/package.json +6 -6
- package/target/dist/index.cjs +74 -58
- package/target/dist/index.cjs.map +1 -1
- package/target/dist/index.d.cts +140 -107
- package/target/dist/index.d.ts +140 -107
- package/target/dist/index.js +68 -57
- package/target/dist/index.js.map +1 -1
- package/target/dist/integrations/effect/index.cjs +145 -13
- package/target/dist/integrations/effect/index.cjs.map +1 -1
- package/target/dist/integrations/effect/index.d.cts +187 -12
- package/target/dist/integrations/effect/index.d.ts +187 -12
- package/target/dist/integrations/effect/index.js +144 -15
- package/target/dist/integrations/effect/index.js.map +1 -1
package/target/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Data, Context, Effect, Layer
|
|
1
|
+
import { Data, Context, Effect, Layer } from 'effect';
|
|
2
2
|
import { NodeSDK } from '@opentelemetry/sdk-node';
|
|
3
3
|
import { SimpleSpanProcessor, BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
|
4
4
|
import { getNodeAutoInstrumentations } from '@opentelemetry/auto-instrumentations-node';
|
|
@@ -683,6 +683,15 @@ var getServiceInfoWithFallback = detectServiceInfo.pipe(
|
|
|
683
683
|
})
|
|
684
684
|
)
|
|
685
685
|
);
|
|
686
|
+
async function detectServiceInfoAsync() {
|
|
687
|
+
return Effect.runPromise(getServiceInfoWithFallback);
|
|
688
|
+
}
|
|
689
|
+
async function getServiceNameAsync() {
|
|
690
|
+
return Effect.runPromise(getServiceName);
|
|
691
|
+
}
|
|
692
|
+
async function getServiceVersionAsync() {
|
|
693
|
+
return Effect.runPromise(getServiceVersion);
|
|
694
|
+
}
|
|
686
695
|
var NodeConfigLoaderLive = ConfigLoaderLive.pipe(
|
|
687
696
|
Layer.provide(Layer.mergeAll(NodeContext.layer, FetchHttpClient.layer))
|
|
688
697
|
);
|
|
@@ -764,7 +773,7 @@ async function loadConfigWithOptions(options = {}) {
|
|
|
764
773
|
|
|
765
774
|
// src/core/sdk-initializer.ts
|
|
766
775
|
var sdkInstance = null;
|
|
767
|
-
var
|
|
776
|
+
var initializationPromise = null;
|
|
768
777
|
function buildHttpInstrumentationConfig(options, config, _otlpEndpoint) {
|
|
769
778
|
const httpConfig = { enabled: true };
|
|
770
779
|
const programmaticPatterns = options.http?.ignoreOutgoingUrls || [];
|
|
@@ -880,38 +889,27 @@ function isTracingAlreadyInitialized() {
|
|
|
880
889
|
return false;
|
|
881
890
|
}
|
|
882
891
|
}
|
|
883
|
-
|
|
892
|
+
async function initializeSdk(options = {}) {
|
|
884
893
|
if (sdkInstance) {
|
|
885
894
|
logger.warn("@atrim/instrumentation: SDK already initialized. Returning existing instance.");
|
|
886
895
|
return sdkInstance;
|
|
887
896
|
}
|
|
888
|
-
if (
|
|
897
|
+
if (initializationPromise) {
|
|
889
898
|
logger.log(
|
|
890
|
-
"@atrim/instrumentation: SDK
|
|
899
|
+
"@atrim/instrumentation: SDK already initialized, waiting for initialization to complete..."
|
|
891
900
|
);
|
|
892
|
-
return
|
|
893
|
-
}
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
);
|
|
905
|
-
return result;
|
|
906
|
-
});
|
|
907
|
-
var performInitializationEffect = (options) => Effect.gen(function* () {
|
|
908
|
-
const config = yield* Effect.tryPromise({
|
|
909
|
-
try: () => loadConfigWithOptions(options),
|
|
910
|
-
catch: (error) => new InitializationError2({
|
|
911
|
-
reason: "Failed to load configuration",
|
|
912
|
-
cause: error
|
|
913
|
-
})
|
|
914
|
-
});
|
|
901
|
+
return initializationPromise;
|
|
902
|
+
}
|
|
903
|
+
initializationPromise = performInitialization(options);
|
|
904
|
+
try {
|
|
905
|
+
const result = await initializationPromise;
|
|
906
|
+
return result;
|
|
907
|
+
} finally {
|
|
908
|
+
initializationPromise = null;
|
|
909
|
+
}
|
|
910
|
+
}
|
|
911
|
+
async function performInitialization(options) {
|
|
912
|
+
const config = await loadConfigWithOptions(options);
|
|
915
913
|
const loggingLevel = config.instrumentation.logging || "on";
|
|
916
914
|
logger.setLevel(loggingLevel);
|
|
917
915
|
const alreadyInitialized = isTracingAlreadyInitialized();
|
|
@@ -927,25 +925,14 @@ var performInitializationEffect = (options) => Effect.gen(function* () {
|
|
|
927
925
|
logger.log("");
|
|
928
926
|
return null;
|
|
929
927
|
}
|
|
930
|
-
const serviceInfo =
|
|
931
|
-
Effect.catchAll(
|
|
932
|
-
() => Effect.succeed({
|
|
933
|
-
name: "unknown-service",
|
|
934
|
-
version: void 0
|
|
935
|
-
})
|
|
936
|
-
)
|
|
937
|
-
);
|
|
928
|
+
const serviceInfo = await detectServiceInfoAsync();
|
|
938
929
|
const serviceName = options.serviceName || serviceInfo.name;
|
|
939
930
|
const serviceVersion = options.serviceVersion || serviceInfo.version;
|
|
940
|
-
const rawExporter =
|
|
941
|
-
const exporter =
|
|
931
|
+
const rawExporter = createOtlpExporter(options.otlp);
|
|
932
|
+
const exporter = new SafeSpanExporter(rawExporter);
|
|
942
933
|
const useSimpleProcessor = process.env.NODE_ENV === "test" || process.env.OTEL_USE_SIMPLE_PROCESSOR === "true";
|
|
943
|
-
const baseProcessor =
|
|
944
|
-
|
|
945
|
-
);
|
|
946
|
-
const patternProcessor = yield* Effect.sync(
|
|
947
|
-
() => new PatternSpanProcessor(config, baseProcessor)
|
|
948
|
-
);
|
|
934
|
+
const baseProcessor = useSimpleProcessor ? new SimpleSpanProcessor(exporter) : new BatchSpanProcessor(exporter);
|
|
935
|
+
const patternProcessor = new PatternSpanProcessor(config, baseProcessor);
|
|
949
936
|
const instrumentations = [];
|
|
950
937
|
const hasWebFramework = hasWebFrameworkInstalled();
|
|
951
938
|
const enableAutoInstrumentation = shouldEnableAutoInstrumentation(
|
|
@@ -958,11 +945,15 @@ var performInitializationEffect = (options) => Effect.gen(function* () {
|
|
|
958
945
|
const undiciConfig = buildUndiciInstrumentationConfig(options, config);
|
|
959
946
|
instrumentations.push(
|
|
960
947
|
...getNodeAutoInstrumentations({
|
|
948
|
+
// Enable HTTP instrumentation with filtering (for http/https modules)
|
|
961
949
|
"@opentelemetry/instrumentation-http": httpConfig,
|
|
950
|
+
// Enable undici instrumentation with filtering (for fetch API)
|
|
962
951
|
"@opentelemetry/instrumentation-undici": undiciConfig,
|
|
952
|
+
// Enable web framework instrumentations
|
|
963
953
|
"@opentelemetry/instrumentation-express": { enabled: true },
|
|
964
954
|
"@opentelemetry/instrumentation-fastify": { enabled: true },
|
|
965
955
|
"@opentelemetry/instrumentation-koa": { enabled: true },
|
|
956
|
+
// Disable noisy instrumentations by default
|
|
966
957
|
"@opentelemetry/instrumentation-fs": { enabled: false },
|
|
967
958
|
"@opentelemetry/instrumentation-dns": { enabled: false }
|
|
968
959
|
})
|
|
@@ -990,20 +981,18 @@ var performInitializationEffect = (options) => Effect.gen(function* () {
|
|
|
990
981
|
serviceName,
|
|
991
982
|
...serviceVersion && { serviceVersion },
|
|
992
983
|
instrumentations,
|
|
984
|
+
// Allow advanced overrides
|
|
993
985
|
...options.sdk
|
|
994
986
|
};
|
|
995
|
-
const sdk =
|
|
996
|
-
|
|
997
|
-
s.start();
|
|
998
|
-
return s;
|
|
999
|
-
});
|
|
987
|
+
const sdk = new NodeSDK(sdkConfig);
|
|
988
|
+
sdk.start();
|
|
1000
989
|
sdkInstance = sdk;
|
|
1001
990
|
if (!options.disableAutoShutdown) {
|
|
1002
|
-
|
|
991
|
+
registerShutdownHandlers(sdk);
|
|
1003
992
|
}
|
|
1004
993
|
logInitialization(config, serviceName, serviceVersion, options, enableAutoInstrumentation);
|
|
1005
994
|
return sdk;
|
|
1006
|
-
}
|
|
995
|
+
}
|
|
1007
996
|
function getSdkInstance() {
|
|
1008
997
|
return sdkInstance;
|
|
1009
998
|
}
|
|
@@ -1016,7 +1005,7 @@ async function shutdownSdk() {
|
|
|
1016
1005
|
}
|
|
1017
1006
|
function resetSdk() {
|
|
1018
1007
|
sdkInstance = null;
|
|
1019
|
-
|
|
1008
|
+
initializationPromise = null;
|
|
1020
1009
|
}
|
|
1021
1010
|
function registerShutdownHandlers(sdk) {
|
|
1022
1011
|
const shutdown = async (signal) => {
|
|
@@ -1073,8 +1062,30 @@ function logInitialization(config, serviceName, serviceVersion, options, autoIns
|
|
|
1073
1062
|
}
|
|
1074
1063
|
|
|
1075
1064
|
// src/api.ts
|
|
1076
|
-
|
|
1077
|
-
const sdk =
|
|
1065
|
+
async function initializeInstrumentation(options = {}) {
|
|
1066
|
+
const sdk = await initializeSdk(options);
|
|
1067
|
+
if (sdk) {
|
|
1068
|
+
const config = await loadConfigWithOptions(options);
|
|
1069
|
+
initializePatternMatcher(config);
|
|
1070
|
+
}
|
|
1071
|
+
return sdk;
|
|
1072
|
+
}
|
|
1073
|
+
async function initializePatternMatchingOnly(options = {}) {
|
|
1074
|
+
const config = await loadConfigWithOptions(options);
|
|
1075
|
+
initializePatternMatcher(config);
|
|
1076
|
+
logger.log("@atrim/instrumentation: Pattern matching initialized (legacy mode)");
|
|
1077
|
+
logger.log(
|
|
1078
|
+
" Note: NodeSDK is not initialized. Use initializeInstrumentation() for complete setup."
|
|
1079
|
+
);
|
|
1080
|
+
}
|
|
1081
|
+
var initializeInstrumentationEffect = (options = {}) => Effect.gen(function* () {
|
|
1082
|
+
const sdk = yield* Effect.tryPromise({
|
|
1083
|
+
try: () => initializeSdk(options),
|
|
1084
|
+
catch: (error) => new InitializationError2({
|
|
1085
|
+
reason: "SDK initialization failed",
|
|
1086
|
+
cause: error
|
|
1087
|
+
})
|
|
1088
|
+
});
|
|
1078
1089
|
if (sdk) {
|
|
1079
1090
|
yield* Effect.tryPromise({
|
|
1080
1091
|
try: () => loadConfigWithOptions(options),
|
|
@@ -1092,7 +1103,7 @@ var initializeInstrumentation = (options = {}) => Effect.gen(function* () {
|
|
|
1092
1103
|
}
|
|
1093
1104
|
return sdk;
|
|
1094
1105
|
});
|
|
1095
|
-
var
|
|
1106
|
+
var initializePatternMatchingOnlyEffect = (options = {}) => Effect.gen(function* () {
|
|
1096
1107
|
const config = yield* Effect.tryPromise({
|
|
1097
1108
|
try: () => loadConfigWithOptions(options),
|
|
1098
1109
|
catch: (error) => new ConfigError2({
|
|
@@ -1102,7 +1113,7 @@ var initializePatternMatchingOnly = (options = {}) => Effect.gen(function* () {
|
|
|
1102
1113
|
});
|
|
1103
1114
|
yield* Effect.sync(() => {
|
|
1104
1115
|
initializePatternMatcher(config);
|
|
1105
|
-
logger.log("@atrim/instrumentation: Pattern matching initialized (
|
|
1116
|
+
logger.log("@atrim/instrumentation: Pattern matching initialized (legacy mode)");
|
|
1106
1117
|
logger.log(
|
|
1107
1118
|
" Note: NodeSDK is not initialized. Use initializeInstrumentation() for complete setup."
|
|
1108
1119
|
);
|
|
@@ -1203,6 +1214,6 @@ function suppressShutdownErrors() {
|
|
|
1203
1214
|
});
|
|
1204
1215
|
}
|
|
1205
1216
|
|
|
1206
|
-
export { ConfigError2 as ConfigError, ConfigFileError2 as ConfigFileError, ConfigUrlError2 as ConfigUrlError, ConfigValidationError2 as ConfigValidationError, ExportError2 as ExportError, InitializationError2 as InitializationError, PatternMatcher, PatternSpanProcessor, ServiceDetectionError2 as ServiceDetectionError, ShutdownError2 as ShutdownError, annotateCacheOperation, annotateDbQuery, annotateHttpRequest, _resetConfigLoaderCache as clearConfigCache, createOtlpExporter, detectServiceInfo, getOtlpEndpoint, getPatternMatcher, getSdkInstance, getServiceInfoWithFallback, getServiceName, getServiceVersion, initializeInstrumentation, initializePatternMatchingOnly, loadConfig, loadConfigFromInline, loadConfigWithOptions, markSpanError, markSpanSuccess, recordException, resetSdk, setSpanAttributes, shouldInstrumentSpan, shutdownSdk, suppressShutdownErrors };
|
|
1217
|
+
export { ConfigError2 as ConfigError, ConfigFileError2 as ConfigFileError, ConfigUrlError2 as ConfigUrlError, ConfigValidationError2 as ConfigValidationError, ExportError2 as ExportError, InitializationError2 as InitializationError, PatternMatcher, PatternSpanProcessor, ServiceDetectionError2 as ServiceDetectionError, ShutdownError2 as ShutdownError, annotateCacheOperation, annotateDbQuery, annotateHttpRequest, _resetConfigLoaderCache as clearConfigCache, createOtlpExporter, detectServiceInfoAsync as detectServiceInfo, detectServiceInfo as detectServiceInfoEffect, getOtlpEndpoint, getPatternMatcher, getSdkInstance, getServiceInfoWithFallback, getServiceNameAsync as getServiceName, getServiceName as getServiceNameEffect, getServiceVersionAsync as getServiceVersion, getServiceVersion as getServiceVersionEffect, initializeInstrumentation, initializeInstrumentationEffect, initializePatternMatchingOnly, initializePatternMatchingOnlyEffect, loadConfig, loadConfigFromInline, loadConfigWithOptions, markSpanError, markSpanSuccess, recordException, resetSdk, setSpanAttributes, shouldInstrumentSpan, shutdownSdk, suppressShutdownErrors };
|
|
1207
1218
|
//# sourceMappingURL=index.js.map
|
|
1208
1219
|
//# sourceMappingURL=index.js.map
|