@uphold/opentelemetry-instrumentation-connect-node
Version:
OpenTelemetry instrumentation for `@connectrpc/connect-node` RPC client and server
83 lines • 3.77 kB
JavaScript
"use strict";
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ConnectNodeInstrumentation = void 0;
const instrumentation_1 = require("@opentelemetry/instrumentation");
const interceptor_1 = require("./interceptor");
const package_json_1 = __importDefault(require("../package.json"));
class ConnectNodeInstrumentation extends instrumentation_1.InstrumentationBase {
constructor(config = {}) {
super('@uphold/opentelemetry-instrumentation-connect-node', package_json_1.default.version, config);
}
init() {
return [
new instrumentation_1.InstrumentationNodeModuleDefinition('@connectrpc/connect-node', ['^2.0.0'], moduleExports => {
this._wrap(moduleExports, 'createConnectTransport', this._patchCreateConnectTransport());
this._wrap(moduleExports, 'createGrpcTransport', this._patchCreateGrpcTransport());
this._wrap(moduleExports, 'createGrpcWebTransport', this._patchCreateGrpcWebTransport());
this._wrap(moduleExports, 'connectNodeAdapter', this._patchConnectNodeAdapter());
return moduleExports;
}, moduleExports => {
if (moduleExports === undefined) {
return;
}
this._unwrap(moduleExports, 'createConnectTransport');
this._unwrap(moduleExports, 'createGrpcTransport');
this._unwrap(moduleExports, 'createGrpcWebTransport');
this._unwrap(moduleExports, 'connectNodeAdapter');
})
];
}
_patchCreateConnectTransport() {
return (original) => {
this._diag.debug('patched createConnectTransport');
return (options) => {
const interceptor = (0, interceptor_1.createClientInterceptor)(this.getConfig(), this._diag, this.tracer);
return original({
...options,
interceptors: [interceptor, ...(options.interceptors ?? [])]
});
};
};
}
_patchCreateGrpcTransport() {
return (original) => {
this._diag.debug('patched createGrpcTransport');
return (options) => {
const interceptor = (0, interceptor_1.createClientInterceptor)(this.getConfig(), this._diag, this.tracer);
return original({
...options,
interceptors: [interceptor, ...(options.interceptors ?? [])]
});
};
};
}
_patchCreateGrpcWebTransport() {
return (original) => {
this._diag.debug('patched createGrpcWebTransport');
return (options) => {
const interceptor = (0, interceptor_1.createClientInterceptor)(this.getConfig(), this._diag, this.tracer);
return original({
...options,
interceptors: [interceptor, ...(options.interceptors ?? [])]
});
};
};
}
_patchConnectNodeAdapter() {
return (original) => {
this._diag.debug('patched connectNodeAdapter');
return (options) => {
const interceptor = (0, interceptor_1.createServerInterceptor)(this.getConfig(), this._diag, this.tracer);
return original({
...options,
interceptors: [interceptor, ...(options.interceptors ?? [])]
});
};
};
}
}
exports.ConnectNodeInstrumentation = ConnectNodeInstrumentation;
//# sourceMappingURL=instrumentation.js.map