@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.
362 lines • 15.1 kB
JavaScript
"use strict";
/*
* 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.
*/
var __rest = (this && this.__rest) || function (s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.bundledInstrumentations = void 0;
exports.getInstrumentations = getInstrumentations;
exports.configureInstrumentations = configureInstrumentations;
exports.parseOptionsAndConfigureInstrumentations = parseOptionsAndConfigureInstrumentations;
const options_1 = require("../tracing/options");
const logging_1 = require("../logging");
const profiling_1 = require("../profiling");
const metrics_1 = require("../metrics");
const utils_1 = require("../utils");
const graphql_1 = require("./graphql");
const http_1 = require("./http");
const logging_2 = require("./logging");
const redis_1 = require("./redis");
const instrumentation_amqplib_1 = require("@opentelemetry/instrumentation-amqplib");
const instrumentation_aws_sdk_1 = require("@opentelemetry/instrumentation-aws-sdk");
const instrumentation_bunyan_1 = require("@opentelemetry/instrumentation-bunyan");
const instrumentation_cassandra_driver_1 = require("@opentelemetry/instrumentation-cassandra-driver");
const instrumentation_connect_1 = require("@opentelemetry/instrumentation-connect");
const instrumentation_dataloader_1 = require("@opentelemetry/instrumentation-dataloader");
const instrumentation_dns_1 = require("@opentelemetry/instrumentation-dns");
const instrumentation_express_1 = require("@opentelemetry/instrumentation-express");
const otel_1 = require("@fastify/otel");
const instrumentation_generic_pool_1 = require("@opentelemetry/instrumentation-generic-pool");
const instrumentation_graphql_1 = require("@opentelemetry/instrumentation-graphql");
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
const instrumentation_hapi_1 = require("@opentelemetry/instrumentation-hapi");
const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
const instrumentation_ioredis_1 = require("@opentelemetry/instrumentation-ioredis");
const instrumentation_kafkajs_1 = require("@opentelemetry/instrumentation-kafkajs");
const instrumentation_knex_1 = require("@opentelemetry/instrumentation-knex");
const instrumentation_koa_1 = require("@opentelemetry/instrumentation-koa");
const instrumentation_lru_memoizer_1 = require("@opentelemetry/instrumentation-lru-memoizer");
const instrumentation_memcached_1 = require("@opentelemetry/instrumentation-memcached");
const instrumentation_mongodb_1 = require("@opentelemetry/instrumentation-mongodb");
const instrumentation_mongoose_1 = require("@opentelemetry/instrumentation-mongoose");
const instrumentation_mysql_1 = require("@opentelemetry/instrumentation-mysql");
const instrumentation_mysql2_1 = require("@opentelemetry/instrumentation-mysql2");
const instrumentation_nestjs_core_1 = require("@opentelemetry/instrumentation-nestjs-core");
const neo4j_1 = require("./external/neo4j");
const instrumentation_net_1 = require("@opentelemetry/instrumentation-net");
const instrumentation_openai_1 = require("@opentelemetry/instrumentation-openai");
const instrumentation_oracledb_1 = require("@opentelemetry/instrumentation-oracledb");
const instrumentation_pg_1 = require("@opentelemetry/instrumentation-pg");
const instrumentation_pino_1 = require("@opentelemetry/instrumentation-pino");
const instrumentation_redis_1 = require("@opentelemetry/instrumentation-redis");
const instrumentation_restify_1 = require("@opentelemetry/instrumentation-restify");
const instrumentation_router_1 = require("@opentelemetry/instrumentation-router");
const instrumentation_socket_io_1 = require("@opentelemetry/instrumentation-socket.io");
const instrumentation_tedious_1 = require("@opentelemetry/instrumentation-tedious");
const instrumentation_winston_1 = require("@opentelemetry/instrumentation-winston");
const elasticsearch_1 = require("./external/elasticsearch");
const sequelize_1 = require("./external/sequelize");
const instrumentation_typeorm_1 = require("@opentelemetry/instrumentation-typeorm");
const instrumentation_undici_1 = require("@opentelemetry/instrumentation-undici");
const nocode_1 = require("./external/nocode");
const httpdc_1 = require("./httpdc/httpdc");
exports.bundledInstrumentations = [
{
create: () => new instrumentation_amqplib_1.AmqplibInstrumentation(),
shortName: 'amqplib',
},
{
create: () => new instrumentation_aws_sdk_1.AwsInstrumentation(),
shortName: 'aws_sdk',
},
{
create: () => new instrumentation_bunyan_1.BunyanInstrumentation(),
shortName: 'bunyan',
},
{
create: () => new instrumentation_cassandra_driver_1.CassandraDriverInstrumentation(),
shortName: 'cassandra_driver',
},
{
create: () => new instrumentation_connect_1.ConnectInstrumentation(),
shortName: 'connect',
},
{
create: () => new instrumentation_dataloader_1.DataloaderInstrumentation(),
shortName: 'dataloader',
},
{
create: () => new instrumentation_dns_1.DnsInstrumentation(),
shortName: 'dns',
},
{
create: () => new instrumentation_express_1.ExpressInstrumentation(),
shortName: 'express',
},
{
create: () => new otel_1.FastifyOtelInstrumentation(),
shortName: 'fastify',
},
{
create: () => new instrumentation_generic_pool_1.GenericPoolInstrumentation(),
shortName: 'generic_pool',
},
{
create: () => new instrumentation_graphql_1.GraphQLInstrumentation(),
shortName: 'graphql',
},
{
create: () => new instrumentation_grpc_1.GrpcInstrumentation(),
shortName: 'grpc',
},
{
create: () => new instrumentation_hapi_1.HapiInstrumentation(),
shortName: 'hapi',
},
{
create: () => new instrumentation_http_1.HttpInstrumentation(),
shortName: 'http',
},
{
create: () => new instrumentation_ioredis_1.IORedisInstrumentation(),
shortName: 'ioredis',
},
{
create: () => new instrumentation_kafkajs_1.KafkaJsInstrumentation(),
shortName: 'kafkajs',
},
{
create: () => new instrumentation_knex_1.KnexInstrumentation(),
shortName: 'knex',
},
{
create: () => new instrumentation_koa_1.KoaInstrumentation(),
shortName: 'koa',
},
{
create: () => new instrumentation_lru_memoizer_1.LruMemoizerInstrumentation(),
shortName: 'lru_memoizer',
},
{
create: () => new instrumentation_memcached_1.MemcachedInstrumentation(),
shortName: 'memcached',
},
{
create: () => new instrumentation_mongodb_1.MongoDBInstrumentation(),
shortName: 'mongodb',
},
{
create: () => new instrumentation_mongoose_1.MongooseInstrumentation(),
shortName: 'mongoose',
},
{
create: () => new instrumentation_mysql_1.MySQLInstrumentation(),
shortName: 'mysql',
},
{
create: () => new instrumentation_mysql2_1.MySQL2Instrumentation(),
shortName: 'mysql2',
},
{
create: () => new neo4j_1.Neo4jInstrumentation(),
shortName: 'neo4j',
},
{
create: () => new instrumentation_nestjs_core_1.NestInstrumentation(),
shortName: 'nestjs_core',
},
{
create: () => new instrumentation_net_1.NetInstrumentation(),
shortName: 'net',
},
{
create: () => new nocode_1.NoCodeInstrumentation(),
shortName: 'nocode',
},
{
create: () => new instrumentation_openai_1.OpenAIInstrumentation(),
shortName: 'openai',
},
{
create: () => new instrumentation_oracledb_1.OracleInstrumentation(),
shortName: 'oracle',
},
{
create: () => new instrumentation_pg_1.PgInstrumentation(),
shortName: 'pg',
},
{
create: () => new instrumentation_pino_1.PinoInstrumentation(),
shortName: 'pino',
},
{
create: () => new instrumentation_redis_1.RedisInstrumentation(),
shortName: 'redis',
},
{
create: () => new instrumentation_restify_1.RestifyInstrumentation(),
shortName: 'restify',
},
{
create: () => new instrumentation_router_1.RouterInstrumentation(),
shortName: 'router',
},
{
create: () => new instrumentation_socket_io_1.SocketIoInstrumentation(),
shortName: 'socketio',
},
{
create: () => new instrumentation_tedious_1.TediousInstrumentation(),
shortName: 'tedious',
},
{
create: () => new instrumentation_winston_1.WinstonInstrumentation(),
shortName: 'winston',
},
{
create: () => new elasticsearch_1.ElasticsearchInstrumentation(),
shortName: 'elasticsearch',
},
{
create: () => new sequelize_1.SequelizeInstrumentation(),
shortName: 'sequelize',
},
{
create: () => new instrumentation_typeorm_1.TypeormInstrumentation(),
shortName: 'typeorm',
},
{
create: () => new instrumentation_undici_1.UndiciInstrumentation(),
shortName: 'undici',
},
{
create: () => new httpdc_1.HttpDcInstrumentation(),
shortName: 'httpdc',
enabledByDefault: false,
},
];
function envKey(info) {
return `OTEL_INSTRUMENTATION_${info.shortName.toUpperCase()}_ENABLED`;
}
function getInstrumentationsToLoad() {
const enabledByDefault = (0, utils_1.getEnvBoolean)('OTEL_INSTRUMENTATION_COMMON_DEFAULT_ENABLED', true);
const instrumentations = exports.bundledInstrumentations.filter((info) => {
var _a;
return (0, utils_1.getEnvBoolean)(envKey(info), (_a = info.enabledByDefault) !== null && _a !== void 0 ? _a : enabledByDefault);
});
const httpInstrumentation = instrumentations.find((i) => i.shortName === 'http');
const httpDcInstrumentation = instrumentations.find((i) => i.shortName === 'httpdc');
if (httpInstrumentation !== undefined &&
httpDcInstrumentation !== undefined) {
throw new Error('Can not enable both HTTP and the experimental HTTPDC instrumentation.');
}
return instrumentations;
}
function getInstrumentations() {
const instrumentations = [];
for (const desc of getInstrumentationsToLoad()) {
instrumentations.push(desc.create());
}
return instrumentations;
}
function configureInstrumentations(options) {
const instrumentations = options.tracing.instrumentations || [];
for (const instrumentation of instrumentations) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const instr = instrumentation;
switch (instr['instrumentationName']) {
case '@opentelemetry/instrumentation-graphql':
(0, graphql_1.configureGraphQlInstrumentation)(instr, options.tracing);
break;
case '@opentelemetry/instrumentation-http':
(0, http_1.configureHttpInstrumentation)(instr, options.tracing);
break;
case '@opentelemetry/instrumentation-httpdc':
(0, http_1.configureHttpDcInstrumentation)(instr, options.tracing);
break;
case '@opentelemetry/instrumentation-redis':
(0, redis_1.configureRedisInstrumentation)(instr, options.tracing);
break;
case '@opentelemetry/instrumentation-bunyan':
case '@opentelemetry/instrumentation-pino':
case '@opentelemetry/instrumentation-winston':
(0, logging_2.disableLogSending)(instr);
(0, logging_2.configureLogInjection)(instr);
break;
}
}
}
function coalesceOptions(options, common) {
var _a, _b, _c, _d, _e;
options.serviceName = (_a = options.serviceName) !== null && _a !== void 0 ? _a : common.serviceName;
options.endpoint = (_b = options.endpoint) !== null && _b !== void 0 ? _b : common.endpoint;
options.accessToken = (_c = options.accessToken) !== null && _c !== void 0 ? _c : common.accessToken;
options.resourceFactory = (_d = options.resourceFactory) !== null && _d !== void 0 ? _d : common.resource;
options.realm = (_e = options.realm) !== null && _e !== void 0 ? _e : common.realm;
return options;
}
function setupTracingOptions(common, tracing) {
const opts = coalesceOptions(tracing, common);
return (0, options_1._setDefaultOptions)(opts);
}
function setupProfilingOptions(common, profiling) {
const opts = coalesceOptions(profiling, common);
return (0, profiling_1._setDefaultOptions)(opts);
}
function setupMetricsOptions(common, metrics) {
const opts = coalesceOptions(metrics, common);
return (0, metrics_1._setDefaultOptions)(opts);
}
function setupLoggingOptions(common, logging) {
const opts = coalesceOptions(logging, common);
return (0, logging_1._setDefaultOptions)(opts);
}
function signalStartOpt(options) {
if (typeof options === 'object') {
return options;
}
return {};
}
function parseOptionsAndConfigureInstrumentations(options = {}) {
const { metrics, profiling, tracing, logging } = options, commonOptions = __rest(options, ["metrics", "profiling", "tracing", "logging"]);
(0, utils_1.assertNoExtraneousProperties)(commonOptions, [
'accessToken',
'endpoint',
'realm',
'serviceName',
'logLevel',
'resource',
]);
const tracingOptions = setupTracingOptions(commonOptions, signalStartOpt(tracing));
const metricsOptions = setupMetricsOptions(commonOptions, signalStartOpt(metrics));
const profilingOptions = setupProfilingOptions(commonOptions, signalStartOpt(profiling));
const loggingOptions = setupLoggingOptions(commonOptions, signalStartOpt(logging));
configureInstrumentations({
tracing: tracingOptions,
logging: loggingOptions,
});
return { tracingOptions, loggingOptions, profilingOptions, metricsOptions };
}
//# sourceMappingURL=index.js.map