Skip to content

Commit

Permalink
chore: add tracing instrumentation on LocalBroker
Browse files Browse the repository at this point in the history
  • Loading branch information
ricardogarim committed Oct 24, 2024
1 parent b0f721e commit 633441b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions packages/core-services/src/LocalBroker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { EventEmitter } from 'events';

import { InstanceStatus } from '@rocket.chat/models';
import { injectCurrentContext, tracerActiveSpan } from '@rocket.chat/tracing';

import { asyncLocalStorage } from '.';
import type { EventSignatures } from './events/Events';
Expand All @@ -17,17 +18,22 @@ export class LocalBroker implements IBroker {
private services = new Set<IServiceClass>();

async call(method: string, data: any): Promise<any> {
const result = await asyncLocalStorage.run(
{
id: 'ctx.id',
nodeID: 'ctx.nodeID',
requestID: 'ctx.requestID',
broker: this,
return tracerActiveSpan(
`action ${method}`,
{},
() => {
return asyncLocalStorage.run(
{
id: 'ctx.id',
nodeID: 'ctx.nodeID',
requestID: 'ctx.requestID',
broker: this,
},
(): any => this.methods.get(method)?.(...data),
);
},
(): any => this.methods.get(method)?.(...data),
injectCurrentContext(),
);

return result;
}

async destroyService(instance: ServiceClass): Promise<void> {
Expand Down

0 comments on commit 633441b

Please sign in to comment.