mirror of
https://github.com/fluencelabs/fluence-js.git
synced 2024-12-05 02:10:18 +00:00
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 <shamsartem@gmail.com>
This commit is contained in:
parent
9821183d53
commit
771086fddf
2
packages/core/js-peer/aqua/tracing.aqua
Normal file
2
packages/core/js-peer/aqua/tracing.aqua
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
service Tracing("tracingSrv"):
|
||||||
|
tracingEvent(arrowName: string, event: string)
|
@ -11,8 +11,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "tsc",
|
"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",
|
"repository": "https://github.com/fluencelabs/fluence-js",
|
||||||
"author": "Fluence Labs",
|
"author": "Fluence Labs",
|
||||||
@ -49,7 +48,6 @@
|
|||||||
"@multiformats/multiaddr": "11.3.0"
|
"@multiformats/multiaddr": "11.3.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@fluencelabs/cli": "0.3.9",
|
|
||||||
"@fluencelabs/aqua-api": "0.9.3",
|
"@fluencelabs/aqua-api": "0.9.3",
|
||||||
"@fluencelabs/aqua-lib": "0.6.0",
|
"@fluencelabs/aqua-lib": "0.6.0",
|
||||||
"@fluencelabs/fluence-network-environment": "1.0.13",
|
"@fluencelabs/fluence-network-environment": "1.0.13",
|
||||||
|
@ -29,9 +29,11 @@ import { concatMap, filter, pipe, Subject, tap, Unsubscribable } from 'rxjs';
|
|||||||
import { defaultSigGuard, Sig } from '../services/Sig.js';
|
import { defaultSigGuard, Sig } from '../services/Sig.js';
|
||||||
import { registerSig } from '../services/_aqua/services.js';
|
import { registerSig } from '../services/_aqua/services.js';
|
||||||
import { registerSrv } from '../services/_aqua/single-module-srv.js';
|
import { registerSrv } from '../services/_aqua/single-module-srv.js';
|
||||||
|
import { registerTracing } from '../services/_aqua/tracing.js';
|
||||||
import { Buffer } from 'buffer';
|
import { Buffer } from 'buffer';
|
||||||
|
|
||||||
import { Srv } from '../services/SingleModuleSrv.js';
|
import { Srv } from '../services/SingleModuleSrv.js';
|
||||||
|
import { Tracing } from '../services/Tracing.js';
|
||||||
|
|
||||||
import { logger } from '../util/logger.js';
|
import { logger } from '../util/logger.js';
|
||||||
import { getParticleContext, registerDefaultServices, ServiceError } from '../jsServiceHost/serviceUtils.js';
|
import { getParticleContext, registerDefaultServices, ServiceError } from '../jsServiceHost/serviceUtils.js';
|
||||||
@ -257,6 +259,7 @@ export abstract class FluencePeer {
|
|||||||
private _classServices: {
|
private _classServices: {
|
||||||
sig: Sig;
|
sig: Sig;
|
||||||
srv: Srv;
|
srv: Srv;
|
||||||
|
tracing: Tracing;
|
||||||
};
|
};
|
||||||
|
|
||||||
private isInitialized = false;
|
private isInitialized = false;
|
||||||
@ -266,6 +269,7 @@ export abstract class FluencePeer {
|
|||||||
this._classServices = {
|
this._classServices = {
|
||||||
sig: new Sig(this.keyPair),
|
sig: new Sig(this.keyPair),
|
||||||
srv: new Srv(this),
|
srv: new Srv(this),
|
||||||
|
tracing: new Tracing(),
|
||||||
};
|
};
|
||||||
|
|
||||||
const peerId = this.keyPair.getPeerId();
|
const peerId = this.keyPair.getPeerId();
|
||||||
@ -275,8 +279,8 @@ export abstract class FluencePeer {
|
|||||||
this._classServices.sig.securityGuard = defaultSigGuard(peerId);
|
this._classServices.sig.securityGuard = defaultSigGuard(peerId);
|
||||||
registerSig(this, 'sig', this._classServices.sig);
|
registerSig(this, 'sig', this._classServices.sig);
|
||||||
registerSig(this, peerId, this._classServices.sig);
|
registerSig(this, peerId, this._classServices.sig);
|
||||||
|
|
||||||
registerSrv(this, 'single_module_srv', this._classServices.srv);
|
registerSrv(this, 'single_module_srv', this._classServices.srv);
|
||||||
|
registerTracing(this, 'tracingSrv', this._classServices.tracing);
|
||||||
}
|
}
|
||||||
|
|
||||||
private _startParticleProcessing() {
|
private _startParticleProcessing() {
|
||||||
|
24
packages/core/js-peer/src/services/Tracing.ts
Normal file
24
packages/core/js-peer/src/services/Tracing.ts
Normal file
@ -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);
|
||||||
|
}
|
||||||
|
}
|
@ -1,10 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
* This compiled aqua file was modified to make it work in monorepo
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
|
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
|
||||||
import { registerService } from '../../compilerSupport/registerService.js';
|
import { registerService } from '../../compilerSupport/registerService.js';
|
||||||
@ -22,9 +17,9 @@ export interface NodeUtilsDef {
|
|||||||
|
|
||||||
export function registerNodeUtils(peer: IFluenceInternalApi, serviceId: string, service: any) {
|
export function registerNodeUtils(peer: IFluenceInternalApi, serviceId: string, service: any) {
|
||||||
registerService({
|
registerService({
|
||||||
peer: peer,
|
peer,
|
||||||
service: service,
|
service,
|
||||||
serviceId: serviceId,
|
serviceId,
|
||||||
def: {
|
def: {
|
||||||
defaultServiceId: 'node_utils',
|
defaultServiceId: 'node_utils',
|
||||||
functions: {
|
functions: {
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
* This compiled aqua file was modified to make it work in monorepo
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
|
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
|
||||||
import { registerService } from '../../compilerSupport/registerService.js';
|
import { registerService } from '../../compilerSupport/registerService.js';
|
||||||
@ -28,9 +23,9 @@ export interface SigDef {
|
|||||||
|
|
||||||
export function registerSig(peer: IFluenceInternalApi, serviceId: string, service: any) {
|
export function registerSig(peer: IFluenceInternalApi, serviceId: string, service: any) {
|
||||||
registerService({
|
registerService({
|
||||||
peer: peer as any,
|
peer,
|
||||||
service: service,
|
service,
|
||||||
serviceId: serviceId,
|
serviceId,
|
||||||
def: {
|
def: {
|
||||||
defaultServiceId: 'sig',
|
defaultServiceId: 'sig',
|
||||||
functions: {
|
functions: {
|
||||||
|
@ -1,10 +1,5 @@
|
|||||||
/**
|
/**
|
||||||
*
|
* This compiled aqua file was modified to make it work in monorepo
|
||||||
* 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
|
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
|
import { CallParams, IFluenceInternalApi } from '@fluencelabs/interfaces';
|
||||||
import { registerService } from '../../compilerSupport/registerService.js';
|
import { registerService } from '../../compilerSupport/registerService.js';
|
||||||
@ -27,7 +22,7 @@ export interface SrvDef {
|
|||||||
|
|
||||||
export function registerSrv(peer: IFluenceInternalApi, serviceId: string, service: any) {
|
export function registerSrv(peer: IFluenceInternalApi, serviceId: string, service: any) {
|
||||||
registerService({
|
registerService({
|
||||||
peer: peer as any,
|
peer,
|
||||||
serviceId,
|
serviceId,
|
||||||
service,
|
service,
|
||||||
def: {
|
def: {
|
||||||
|
52
packages/core/js-peer/src/services/_aqua/tracing.ts
Normal file
52
packages/core/js-peer/src/services/_aqua/tracing.ts
Normal file
@ -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
|
7115
pnpm-lock.yaml
generated
7115
pnpm-lock.yaml
generated
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user