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

Commit 771086f

Browse files
feat: Add tracing service [fixes DXJ-388] (#307)
* Add default tracing service * fix formatting and logger * use console.log back again * Add default tracing service * fix formatting and logger * use console.log back again * update compiled aqua --------- Co-authored-by: Artsiom Shamsutdzinau <[email protected]>
1 parent 9821183 commit 771086f

File tree

9 files changed

+3542
-3686
lines changed

9 files changed

+3542
-3686
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
service Tracing("tracingSrv"):
2+
tracingEvent(arrowName: string, event: string)

packages/core/js-peer/package.json

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
"type": "module",
1212
"scripts": {
1313
"build": "tsc",
14-
"compile-aqua": "fluence aqua -i ./aqua/ -o ./aqua",
15-
"test": "node ./copy-worker-script-workaround.mjs && vitest --threads false run"
14+
"test": "node ./copy-worker-script-workaround.mjs && vitest --threads false run"
1615
},
1716
"repository": "https://github.com/fluencelabs/fluence-js",
1817
"author": "Fluence Labs",
@@ -49,7 +48,6 @@
4948
"@multiformats/multiaddr": "11.3.0"
5049
},
5150
"devDependencies": {
52-
"@fluencelabs/cli": "0.3.9",
5351
"@fluencelabs/aqua-api": "0.9.3",
5452
"@fluencelabs/aqua-lib": "0.6.0",
5553
"@fluencelabs/fluence-network-environment": "1.0.13",

packages/core/js-peer/src/jsPeer/FluencePeer.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,11 @@ import { concatMap, filter, pipe, Subject, tap, Unsubscribable } from 'rxjs';
2929
import { defaultSigGuard, Sig } from '../services/Sig.js';
3030
import { registerSig } from '../services/_aqua/services.js';
3131
import { registerSrv } from '../services/_aqua/single-module-srv.js';
32+
import { registerTracing } from '../services/_aqua/tracing.js';
3233
import { Buffer } from 'buffer';
3334

3435
import { Srv } from '../services/SingleModuleSrv.js';
36+
import { Tracing } from '../services/Tracing.js';
3537

3638
import { logger } from '../util/logger.js';
3739
import { getParticleContext, registerDefaultServices, ServiceError } from '../jsServiceHost/serviceUtils.js';
@@ -257,6 +259,7 @@ export abstract class FluencePeer {
257259
private _classServices: {
258260
sig: Sig;
259261
srv: Srv;
262+
tracing: Tracing;
260263
};
261264

262265
private isInitialized = false;
@@ -266,6 +269,7 @@ export abstract class FluencePeer {
266269
this._classServices = {
267270
sig: new Sig(this.keyPair),
268271
srv: new Srv(this),
272+
tracing: new Tracing(),
269273
};
270274

271275
const peerId = this.keyPair.getPeerId();
@@ -275,8 +279,8 @@ export abstract class FluencePeer {
275279
this._classServices.sig.securityGuard = defaultSigGuard(peerId);
276280
registerSig(this, 'sig', this._classServices.sig);
277281
registerSig(this, peerId, this._classServices.sig);
278-
279282
registerSrv(this, 'single_module_srv', this._classServices.srv);
283+
registerTracing(this, 'tracingSrv', this._classServices.tracing);
280284
}
281285

282286
private _startParticleProcessing() {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/*
2+
* Copyright 2023 Fluence Labs Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
import { CallParams } from '@fluencelabs/interfaces';
18+
import { TracingDef } from './_aqua/tracing.js';
19+
20+
export class Tracing implements TracingDef {
21+
tracingEvent(arrowName: string, event: string, callParams: CallParams<'arrowName' | 'event'>): void {
22+
console.log('[%s] (%s) %s', callParams.particleId, arrowName, event);
23+
}
24+
}

packages/core/js-peer/src/services/_aqua/node-utils.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/**
2-
*
3-
* This file is auto-generated. Do not edit manually: changes may be erased.
4-
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
5-
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
6-
* Aqua version: 0.7.7-362
7-
*
2+
* This compiled aqua file was modified to make it work in monorepo
83
*/
94
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
105
import { registerService } from '../../compilerSupport/registerService.js';
@@ -22,9 +17,9 @@ export interface NodeUtilsDef {
2217

2318
export function registerNodeUtils(peer: IFluenceInternalApi, serviceId: string, service: any) {
2419
registerService({
25-
peer: peer,
26-
service: service,
27-
serviceId: serviceId,
20+
peer,
21+
service,
22+
serviceId,
2823
def: {
2924
defaultServiceId: 'node_utils',
3025
functions: {

packages/core/js-peer/src/services/_aqua/services.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/**
2-
*
3-
* This file is auto-generated. Do not edit manually: changes may be erased.
4-
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
5-
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
6-
* Aqua version: 0.7.7-362
7-
*
2+
* This compiled aqua file was modified to make it work in monorepo
83
*/
94
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
105
import { registerService } from '../../compilerSupport/registerService.js';
@@ -28,9 +23,9 @@ export interface SigDef {
2823

2924
export function registerSig(peer: IFluenceInternalApi, serviceId: string, service: any) {
3025
registerService({
31-
peer: peer as any,
32-
service: service,
33-
serviceId: serviceId,
26+
peer,
27+
service,
28+
serviceId,
3429
def: {
3530
defaultServiceId: 'sig',
3631
functions: {

packages/core/js-peer/src/services/_aqua/single-module-srv.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,5 @@
11
/**
2-
*
3-
* This file is auto-generated. Do not edit manually: changes may be erased.
4-
* Generated by Aqua compiler: https://github.com/fluencelabs/aqua/.
5-
* If you find any bugs, please write an issue on GitHub: https://github.com/fluencelabs/aqua/issues
6-
* Aqua version: 0.7.7-362
7-
*
2+
* This compiled aqua file was modified to make it work in monorepo
83
*/
94
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
105
import { registerService } from '../../compilerSupport/registerService.js';
@@ -27,7 +22,7 @@ export interface SrvDef {
2722

2823
export function registerSrv(peer: IFluenceInternalApi, serviceId: string, service: any) {
2924
registerService({
30-
peer: peer as any,
25+
peer,
3126
serviceId,
3227
service,
3328
def: {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/**
2+
* This compiled aqua file was modified to make it work in monorepo
3+
*/
4+
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
5+
import { registerService } from '../../compilerSupport/registerService.js';
6+
7+
// Services
8+
9+
export interface TracingDef {
10+
tracingEvent: (
11+
arrowName: string,
12+
event: string,
13+
callParams: CallParams<'arrowName' | 'event'>,
14+
) => void | Promise<void>;
15+
}
16+
17+
export function registerTracing(peer: IFluenceInternalApi, serviceId: string, service: any) {
18+
registerService({
19+
peer,
20+
serviceId,
21+
service,
22+
def: {
23+
defaultServiceId: 'tracingSrv',
24+
functions: {
25+
tag: 'labeledProduct',
26+
fields: {
27+
tracingEvent: {
28+
tag: 'arrow',
29+
domain: {
30+
tag: 'labeledProduct',
31+
fields: {
32+
arrowName: {
33+
tag: 'scalar',
34+
name: 'string',
35+
},
36+
event: {
37+
tag: 'scalar',
38+
name: 'string',
39+
},
40+
},
41+
},
42+
codomain: {
43+
tag: 'nil',
44+
},
45+
},
46+
},
47+
},
48+
},
49+
});
50+
}
51+
52+
// Functions

0 commit comments

Comments
 (0)