diff --git a/src/backend/src/CoreModule.js b/src/backend/src/CoreModule.js index 39137057b..587f0b868 100644 --- a/src/backend/src/CoreModule.js +++ b/src/backend/src/CoreModule.js @@ -220,6 +220,9 @@ const install = async ({ context, services, app, useapi, modapi }) => { const { InformationService } = require('./services/information/InformationService'); services.registerService('information', InformationService); + const { TraceService } = require('./services/TraceService.js'); + services.registerService('traceService', TraceService); + const { FilesystemService } = require('./filesystem/FilesystemService'); services.registerService('filesystem', FilesystemService); diff --git a/src/backend/src/filesystem/FilesystemService.js b/src/backend/src/filesystem/FilesystemService.js index 74c7ec17f..aca09e758 100644 --- a/src/backend/src/filesystem/FilesystemService.js +++ b/src/backend/src/filesystem/FilesystemService.js @@ -18,7 +18,6 @@ */ // TODO: database access can be a service const { RESOURCE_STATUS_PENDING_CREATE } = require('../modules/puterfs/ResourceService.js'); -const { TraceService } = require('../services/TraceService.js'); const { NodePathSelector, NodeUIDSelector, NodeInternalIDSelector, NodeSelector } = require('./node/selectors.js'); const FSNodeContext = require('./FSNodeContext.js'); const { Context } = require('../util/context.js'); @@ -39,11 +38,9 @@ class FilesystemService extends BaseService { config: require('../config.js'), }; - old_constructor(args) { + old_constructor (args) { const { services } = args; - services.registerService('traceService', TraceService); - // The new fs entry service this.log = services.get('log-service').create('filesystem-service'); @@ -61,7 +58,7 @@ class FilesystemService extends BaseService { }); } - async _init() { + async _init () { this.old_constructor({ services: this.services }); const svc_permission = this.services.get('permission'); svc_permission.register_rewriter(PermissionRewriter.create({ @@ -150,7 +147,7 @@ class FilesystemService extends BaseService { })); } - async mkshortcut({ parent, name, user, target }) { + async mkshortcut ({ parent, name, user, target }) { // Access Control { @@ -224,7 +221,7 @@ class FilesystemService extends BaseService { return node; } - async mklink({ parent, name, user, target }) { + async mklink ({ parent, name, user, target }) { // Access Control { @@ -286,7 +283,7 @@ class FilesystemService extends BaseService { return node; } - async update_child_paths(old_path, new_path, user_id) { + async update_child_paths (old_path, new_path, user_id) { const svc_performanceMonitor = this.services.get('performance-monitor'); const monitor = svc_performanceMonitor.createContext('update_child_paths'); @@ -311,7 +308,7 @@ class FilesystemService extends BaseService { * @param {*} location - path, uid, or id associated with a filesystem node * @returns */ - async node(selector) { + async node (selector) { if ( typeof selector === 'string' ) { if ( selector.startsWith('/') ) { selector = new NodePathSelector(selector); @@ -331,13 +328,11 @@ class FilesystemService extends BaseService { selector = new NodeInternalIDSelector('mysql', selector.mysql_id); } } - + if ( ! (selector instanceof NodeSelector) ) { - throw new Error( - 'FileSystemService could not resolve the specified node value ' + - quot(''+selector) + ` (type: ${typeof selector}) ` + - 'to a filesystem node selector', - ); + throw new Error('FileSystemService could not resolve the specified node value ' + + quot('' + selector) + ` (type: ${typeof selector}) ` + + 'to a filesystem node selector'); } system_dir_check: { @@ -397,7 +392,7 @@ class FilesystemService extends BaseService { * @param {*} param0.id please use mysql_id instead * @param {*} param0.mysql_id */ - async get_entry({ path, uid, id, mysql_id, ...options }) { + async get_entry ({ path, uid, id, mysql_id, ...options }) { let fsNode = await this.node({ path, uid, id, mysql_id }); await fsNode.fetchEntry(options); return fsNode.entry; diff --git a/src/backend/src/services/TraceService.js b/src/backend/src/services/TraceService.js index 6a7eb9962..cae54fe8a 100644 --- a/src/backend/src/services/TraceService.js +++ b/src/backend/src/services/TraceService.js @@ -17,8 +17,8 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ -const opentelemetry = require("@opentelemetry/api"); - +const opentelemetry = require('@opentelemetry/api'); +const BaseService = require('./BaseService'); /** * @class TraceService @@ -27,25 +27,21 @@ const opentelemetry = require("@opentelemetry/api"); * It provides methods to start spans, which are used for tracking * operations and measuring performance within the application. */ -class TraceService { - constructor () { - this.tracer_ = opentelemetry.trace.getTracer( - 'puter-filesystem-tracer' - ); +class TraceService extends BaseService { + _construct () { + this.tracer_ = opentelemetry.trace.getTracer('puter-filesystem-tracer'); } - /** * Retrieves the tracer instance used for creating spans. * This method is a getter that returns the current tracer object. - * + * * @returns {import("@opentelemetry/api").Tracer} The tracer instance for this service. */ get tracer () { return this.tracer_; } - /** * Starts an active span for executing a function with tracing. * This method wraps the provided function `fn` in a span, managing @@ -64,14 +60,16 @@ class TraceService { args.push(async span => { try { return await fn({ span }); - } catch (error) { + } catch ( error ) { span.setStatus({ code: opentelemetry.SpanStatusCode.ERROR, message: error.message }); throw error; } finally { span.end(); } }); - this.tracer.startActiveSpan('name', { }, () => {}) + this.tracer.startActiveSpan('name', { }, () => { + // This block intentionally left blank + }); return await this.tracer.startActiveSpan(...args); } }