Repository URL to install this package:
Version:
0.1.7 ▾
|
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const DtraceProbes = require("./lib/binding.js");
const sdk_node_1 = require("@opentelemetry/sdk-node");
const otlp_transformer_1 = require("@odigos/otlp-transformer");
const require_in_the_middle_1 = require("require-in-the-middle");
const shimmer_1 = __importDefault(require("shimmer"));
const instrumentation_connect_1 = require("@opentelemetry/instrumentation-connect");
const instrumentation_grpc_1 = require("@opentelemetry/instrumentation-grpc");
const instrumentation_fastify_1 = require("@opentelemetry/instrumentation-fastify");
const instrumentation_hapi_1 = require("@opentelemetry/instrumentation-hapi");
const instrumentation_http_1 = require("@opentelemetry/instrumentation-http");
const instrumentation_restify_1 = require("@opentelemetry/instrumentation-restify");
const instrumentation_router_1 = require("@opentelemetry/instrumentation-router");
const instrumentation_kafkajs_1 = require("@odigos/instrumentation-kafkajs");
class EBPFSpanProcessor {
onStart(_span, _context) { }
onEnd(_span) {
const data = otlp_transformer_1.ProtobufTraceSerializer.serializeRequest([_span]);
DtraceProbes.SpanEnded(data);
}
shutdown() {
return Promise.resolve();
}
forceFlush() {
return Promise.resolve();
}
}
const odigosInstrumentations = [new instrumentation_connect_1.ConnectInstrumentation(),
new instrumentation_fastify_1.FastifyInstrumentation(),
new instrumentation_hapi_1.HapiInstrumentation(),
new instrumentation_http_1.HttpInstrumentation(),
new instrumentation_restify_1.RestifyInstrumentation(),
new instrumentation_router_1.RouterInstrumentation(),
new instrumentation_grpc_1.GrpcInstrumentation(),
new instrumentation_kafkajs_1.KafkaJsInstrumentation(),
];
let userInstrumentations = [];
let userCalledRegisterInstrumentations = false;
const odigosSpanProcessor = new EBPFSpanProcessor();
const sdk = new sdk_node_1.NodeSDK({
autoDetectResources: false,
instrumentations: odigosInstrumentations,
spanProcessor: odigosSpanProcessor,
});
sdk.start();
new require_in_the_middle_1.Hook(['@opentelemetry/instrumentation'], { internals: true }, function (exports, name) {
if (name === '@opentelemetry/instrumentation/build/src/autoLoader.js') {
shimmer_1.default.wrap(exports, 'registerInstrumentations', function (original) {
return function (options) {
var _a;
const instrumentations = (_a = options.instrumentations) === null || _a === void 0 ? void 0 : _a.flat();
if (!instrumentations) {
return;
}
userInstrumentations = instrumentations;
userCalledRegisterInstrumentations = true;
return original.apply(this, arguments);
};
});
}
return exports;
});
const wrapSetGlobalTracerProvider = (exports) => {
shimmer_1.default.wrap(exports.TraceAPI.prototype, 'setGlobalTracerProvider', function (original) {
return function (tracerProvider) {
if (typeof tracerProvider.addSpanProcessor === 'function') {
tracerProvider.addSpanProcessor(odigosSpanProcessor);
odigosInstrumentations.forEach((instrumentation) => {
instrumentation.setTracerProvider(tracerProvider);
});
userInstrumentations.forEach((instrumentation) => {
instrumentation.setTracerProvider(tracerProvider);
});
} // else - not an instance of NodeTracerProvider, so we can't do much about it.
const res = original.call(this, tracerProvider);
return res;
};
});
};
const wrapRegisterGlobal = (exports) => {
shimmer_1.default.wrap(exports, 'registerGlobal', function (original) {
return function (...args) {
if (args.length < 3) {
// function should be called with 3 or 4 arguments, if not, we ignore it
return original.apply(this, args);
}
// make the call so that the 4th argument is true, which means allowOverride is enabled no matter the original value
args[3] = true;
const res = original.apply(this, args);
return res;
};
});
};
new require_in_the_middle_1.Hook(['@opentelemetry/api'], { internals: true }, function (exports, name) {
switch (name) {
case '@opentelemetry/api/build/src/api/trace.js':
wrapSetGlobalTracerProvider(exports);
break;
case '@opentelemetry/api/build/src/internal/global-utils.js':
wrapRegisterGlobal(exports);
break;
default:
// these are the only files we are interested in
}
return exports;
});