refactor: make TraceService a proper service

This service was registered within FilesystemService for legacy reasons
but now it needs to be accessed by an extension. In order for the
extension import to work as expected this service needs to be registered
at the same phase as other services.
This commit is contained in:
KernelDeimos
2025-11-04 21:12:41 -05:00
committed by Eric Dubé
parent e7357054b0
commit 24b1570007
3 changed files with 24 additions and 28 deletions
+3
View File
@@ -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);
+11 -16
View File
@@ -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;
+10 -12
View File
@@ -17,8 +17,8 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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);
}
}