@ogcio/o11y-sdk-node
Version:
Opentelemetry standard instrumentation SDK for NodeJS based project
34 lines (33 loc) • 1.36 kB
JavaScript
let nodeSDKConfig;
export const setNodeSdkConfig = (config) => {
nodeSDKConfig = config;
};
export const getNodeSdkConfig = () => {
if (!nodeSDKConfig) {
return undefined;
}
// Create a shallow copy and handle non-serializable properties separately.
// Properties like additionalInstrumentations, grpcMetadata, and detection.custom
// contain class instances with circular references that cannot be JSON serialized.
const { additionalInstrumentations, grpcMetadata, autoInstrumentationConfig, detection, ...serializableConfig } = nodeSDKConfig;
// Deep clone the serializable portion of the config
const clonedConfig = /* NOSONAR */ JSON.parse(JSON.stringify(serializableConfig));
// Re-attach non-serializable properties by reference (they should be read-only)
if (additionalInstrumentations) {
clonedConfig.additionalInstrumentations = additionalInstrumentations;
}
if (grpcMetadata) {
clonedConfig.grpcMetadata = grpcMetadata;
}
if (autoInstrumentationConfig) {
clonedConfig.autoInstrumentationConfig = autoInstrumentationConfig;
}
if (detection) {
// Clone detection but keep custom redactors by reference
clonedConfig.detection = {
...detection,
custom: detection.custom,
};
}
return clonedConfig;
};