openlit
Version:
OpenTelemetry-native Auto instrumentation library for monitoring LLM Applications, facilitating the integration of observability into your GenAI-driven projects
43 lines • 1.67 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 constant_1 = require("../../constant");
const wrapper_1 = __importDefault(require("./wrapper"));
class OpenlitOllamaInstrumentation extends instrumentation_1.InstrumentationBase {
constructor(config = {}) {
super(`${constant_1.INSTRUMENTATION_PREFIX}/instrumentation-ollama`, '1.0.0', config);
}
init() {
const module = new instrumentation_1.InstrumentationNodeModuleDefinition('ollama', ['>= 0.5.8'], (moduleExports) => {
this._patch(moduleExports);
return moduleExports;
}, (moduleExports) => {
if (moduleExports !== undefined) {
this._unpatch(moduleExports);
}
});
return [module];
}
manualPatch(ollama) {
this._patch(ollama);
}
_patch(moduleExports) {
try {
if ((0, instrumentation_1.isWrapped)(moduleExports.Ollama.prototype.chat)) {
this._unwrap(moduleExports.Ollama.prototype, 'chat');
}
this._wrap(moduleExports.Ollama.prototype, 'chat', wrapper_1.default._patchChat(this.tracer));
}
catch (e) {
console.error('Error in _patch method:', e);
}
}
_unpatch(moduleExports) {
this._unwrap(moduleExports.Ollama.prototype, 'chat');
}
}
exports.default = OpenlitOllamaInstrumentation;
//# sourceMappingURL=index.js.map