openlit
Version:
OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
58 lines • 2.65 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const instrumentation_1 = require("@opentelemetry/instrumentation");
const openai_1 = __importDefault(require("./openai"));
const anthropic_1 = __importDefault(require("./anthropic"));
const cohere_1 = __importDefault(require("./cohere"));
class Instrumentations {
static setup(tracerProvider, disabledInstrumentations = [], instrumentations) {
if (instrumentations === undefined) {
const filteredInstrumentations = this.getFilteredInstrumentations(disabledInstrumentations);
(0, instrumentation_1.registerInstrumentations)({
instrumentations: filteredInstrumentations.map(([_, instrumentation]) => instrumentation),
tracerProvider,
});
}
else {
const filteredInstrumentations = this.getFilteredInstrumentations(disabledInstrumentations, instrumentations);
filteredInstrumentations.forEach(([k, instrumentation]) => {
if (this.availableInstrumentations[k].setTracerProvider) {
this.availableInstrumentations[k].setTracerProvider(tracerProvider);
}
if (this.availableInstrumentations[k].manualPatch) {
this.availableInstrumentations[k].manualPatch(instrumentation);
}
});
(0, instrumentation_1.registerInstrumentations)({
tracerProvider,
});
}
}
static getFilteredInstrumentations(disabledInstrumentations, instrumentations) {
const availableInstrumentations = instrumentations || this.availableInstrumentations;
return Object.keys(availableInstrumentations)
.filter((k) => {
if (disabledInstrumentations.includes(k)) {
if (typeof availableInstrumentations[k].disable === 'function') {
availableInstrumentations[k].disable();
}
return false;
}
if (typeof availableInstrumentations[k].enable === 'function') {
availableInstrumentations[k].enable();
}
return true;
})
.map((k) => [k, availableInstrumentations[k]]);
}
}
Instrumentations.availableInstrumentations = {
openai: new openai_1.default(),
anthropic: new anthropic_1.default(),
cohere: new cohere_1.default(),
};
exports.default = Instrumentations;
//# sourceMappingURL=index.js.map