@splunk/otel
Version:
The Splunk distribution of OpenTelemetry Node Instrumentation provides a Node agent that automatically instruments your Node application to capture and report distributed traces to Splunk APM.
52 lines • 2.18 kB
JavaScript
;
/*
* Copyright Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.defaultLogHook = void 0;
exports.configureLogInjection = configureLogInjection;
exports.disableLogSending = disableLogSending;
const semantic_conventions_1 = require("@opentelemetry/semantic-conventions");
const utils_1 = require("../utils");
const defaultLogHook = (span, record) => {
const sdkSpan = span;
record['service.name'] = sdkSpan.resource.attributes[semantic_conventions_1.ATTR_SERVICE_NAME];
const version = sdkSpan.resource.attributes[semantic_conventions_1.ATTR_SERVICE_VERSION];
if (version !== undefined) {
record['service.version'] = version;
}
const environment = sdkSpan.resource.attributes[semantic_conventions_1.SEMRESATTRS_DEPLOYMENT_ENVIRONMENT];
if (environment !== undefined) {
record['service.environment'] = environment;
}
};
exports.defaultLogHook = defaultLogHook;
function configureLogInjection(instrumentation) {
const config = instrumentation.getConfig();
if (config === undefined) {
return instrumentation.setConfig({ logHook: exports.defaultLogHook });
}
if (config.logHook === undefined) {
config.logHook = exports.defaultLogHook;
return instrumentation.setConfig(config);
}
}
function disableLogSending(instrumentation) {
const enabled = (0, utils_1.getEnvBoolean)('SPLUNK_AUTOMATIC_LOG_COLLECTION', false);
instrumentation.setConfig(Object.assign({}, instrumentation.getConfig(), {
disableLogSending: !enabled,
}));
}
//# sourceMappingURL=logging.js.map