Skip to content
This repository was archived by the owner on Jul 10, 2025. It is now read-only.

feat: Add tracing service [fixes DXJ-388] #307

Merged
merged 8 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/js-peer/aqua/tracing.aqua
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
service Tracing("tracingSrv"):
tracingEvent(arrowName: string, event: string)
4 changes: 1 addition & 3 deletions packages/core/js-peer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
"type": "module",
"scripts": {
"build": "tsc",
"compile-aqua": "fluence aqua -i ./aqua/ -o ./aqua",
"test": "node ./copy-worker-script-workaround.mjs && vitest --threads false run"
"test": "node ./copy-worker-script-workaround.mjs && vitest --threads false run"
},
"repository": "https://github.com/fluencelabs/fluence-js",
"author": "Fluence Labs",
Expand Down Expand Up @@ -49,7 +48,6 @@
"@multiformats/multiaddr": "11.3.0"
},
"devDependencies": {
"@fluencelabs/cli": "0.3.9",
"@fluencelabs/aqua-api": "0.9.3",
"@fluencelabs/aqua-lib": "0.6.0",
"@fluencelabs/fluence-network-environment": "1.0.13",
Expand Down
6 changes: 5 additions & 1 deletion packages/core/js-peer/src/jsPeer/FluencePeer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ import { concatMap, filter, pipe, Subject, tap, Unsubscribable } from 'rxjs';
import { defaultSigGuard, Sig } from '../services/Sig.js';
import { registerSig } from '../services/_aqua/services.js';
import { registerSrv } from '../services/_aqua/single-module-srv.js';
import { registerTracing } from '../services/_aqua/tracing.js';
import { Buffer } from 'buffer';

import { Srv } from '../services/SingleModuleSrv.js';
import { Tracing } from '../services/Tracing.js';

import { logger } from '../util/logger.js';
import { getParticleContext, registerDefaultServices, ServiceError } from '../jsServiceHost/serviceUtils.js';
Expand Down Expand Up @@ -257,6 +259,7 @@ export abstract class FluencePeer {
private _classServices: {
sig: Sig;
srv: Srv;
tracing: Tracing;
};

private isInitialized = false;
Expand All @@ -266,6 +269,7 @@ export abstract class FluencePeer {
this._classServices = {
sig: new Sig(this.keyPair),
srv: new Srv(this),
tracing: new Tracing(),
};

const peerId = this.keyPair.getPeerId();
Expand All @@ -275,8 +279,8 @@ export abstract class FluencePeer {
this._classServices.sig.securityGuard = defaultSigGuard(peerId);
registerSig(this, 'sig', this._classServices.sig);
registerSig(this, peerId, this._classServices.sig);

registerSrv(this, 'single_module_srv', this._classServices.srv);
registerTracing(this, 'tracingSrv', this._classServices.tracing);
}

private _startParticleProcessing() {
Expand Down
24 changes: 24 additions & 0 deletions packages/core/js-peer/src/services/Tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Copyright 2023 Fluence Labs Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import { CallParams } from '@fluencelabs/interfaces';
import { TracingDef } from './_aqua/tracing.js';

export class Tracing implements TracingDef {
tracingEvent(arrowName: string, event: string, callParams: CallParams<'arrowName' | 'event'>): void {
console.log('[%s] (%s) %s', callParams.particleId, arrowName, event);
}
}
13 changes: 4 additions & 9 deletions packages/core/js-peer/src/services/_aqua/node-utils.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.7.7-362
*
* This compiled aqua file was modified to make it work in monorepo
*/
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
import { registerService } from '../../compilerSupport/registerService.js';
Expand All @@ -22,9 +17,9 @@ export interface NodeUtilsDef {

export function registerNodeUtils(peer: IFluenceInternalApi, serviceId: string, service: any) {
registerService({
peer: peer,
service: service,
serviceId: serviceId,
peer,
service,
serviceId,
def: {
defaultServiceId: 'node_utils',
functions: {
Expand Down
13 changes: 4 additions & 9 deletions packages/core/js-peer/src/services/_aqua/services.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.7.7-362
*
* This compiled aqua file was modified to make it work in monorepo
*/
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
import { registerService } from '../../compilerSupport/registerService.js';
Expand All @@ -28,9 +23,9 @@ export interface SigDef {

export function registerSig(peer: IFluenceInternalApi, serviceId: string, service: any) {
registerService({
peer: peer as any,
service: service,
serviceId: serviceId,
peer,
service,
serviceId,
def: {
defaultServiceId: 'sig',
functions: {
Expand Down
9 changes: 2 additions & 7 deletions packages/core/js-peer/src/services/_aqua/single-module-srv.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
/**
*
* This file is auto-generated. Do not edit manually: changes may be erased.
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
* Aqua version: 0.7.7-362
*
* This compiled aqua file was modified to make it work in monorepo
*/
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
import { registerService } from '../../compilerSupport/registerService.js';
Expand All @@ -27,7 +22,7 @@ export interface SrvDef {

export function registerSrv(peer: IFluenceInternalApi, serviceId: string, service: any) {
registerService({
peer: peer as any,
peer,
serviceId,
service,
def: {
Expand Down
52 changes: 52 additions & 0 deletions packages/core/js-peer/src/services/_aqua/tracing.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* This compiled aqua file was modified to make it work in monorepo
*/
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
import { registerService } from '../../compilerSupport/registerService.js';

// Services

export interface TracingDef {
tracingEvent: (
arrowName: string,
event: string,
callParams: CallParams<'arrowName' | 'event'>,
) => void | Promise<void>;
}

export function registerTracing(peer: IFluenceInternalApi, serviceId: string, service: any) {
registerService({
peer,
serviceId,
service,
def: {
defaultServiceId: 'tracingSrv',
functions: {
tag: 'labeledProduct',
fields: {
tracingEvent: {
tag: 'arrow',
domain: {
tag: 'labeledProduct',
fields: {
arrowName: {
tag: 'scalar',
name: 'string',
},
event: {
tag: 'scalar',
name: 'string',
},
},
},
codomain: {
tag: 'nil',
},
},
},
},
},
});
}

// Functions
Loading