Skip to content
Open
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
11 changes: 5 additions & 6 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"pre-commit": "bun test"
}
},
"packageManager": "bun@1.1.10",
"packageManager": "bun@1.2.23",
"lint-staged": {
"**.{js|ts|cjs|mjs|d.cts|d.mts|jsx|tsx|json|jsonc}": [
"biome check --files-ignore-unknown=true --diagnostic-level=error",
Expand Down
1 change: 1 addition & 0 deletions packages/federation-sdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"test": "bun test"
},
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"@rocket.chat/emitter": "^0.31.25",
"@rocket.chat/federation-core": "workspace:*",
"@rocket.chat/federation-crypto": "workspace:*",
Expand Down
10 changes: 10 additions & 0 deletions packages/federation-sdk/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,16 @@ export {
FederationValidationError,
} from './services/federation-validation.service';

// Tracing utilities - compatible with @rocket.chat/tracing
export {
addSpanAttributes,
traced,
tracedClass,
tracerActiveSpan,
hasActiveSpan,
type ITracedClassOptions,
} from './utils/tracing';

export type HomeserverEventSignatures = {
'homeserver.ping': {
message: string;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { generateId } from '@rocket.chat/federation-core';
import type { EventStagingStore } from '@rocket.chat/federation-core';
import { type EventID, Pdu, RoomID } from '@rocket.chat/federation-room';
import {
type EventID,
type Pdu,
type RoomID,
} from '@rocket.chat/federation-room';
import type { Collection, DeleteResult, UpdateResult } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

@tracedClass({ type: 'repository', className: 'EventStagingRepository' })
@singleton()
export class EventStagingRepository {
constructor(
Expand Down
12 changes: 7 additions & 5 deletions packages/federation-sdk/src/repositories/event.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import { generateId } from '@rocket.chat/federation-core';
import type { EventStore } from '@rocket.chat/federation-core';
import {
type EventID,
Pdu,
PduForType,
PduType,
type Pdu,
type PduForType,
type PduType,
RejectCode,
RoomID,
StateID,
type RoomID,
type StateID,
} from '@rocket.chat/federation-room';
import type {
Collection,
Expand All @@ -18,7 +18,9 @@ import type {
WithId,
} from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

@tracedClass({ type: 'repository', className: 'EventRepository' })
@singleton()
export class EventRepository {
constructor(
Expand Down
4 changes: 3 additions & 1 deletion packages/federation-sdk/src/repositories/key.repository.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Collection } from 'mongodb';
import type { Collection } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

export type Key = {
origin: string;
Expand All @@ -8,6 +9,7 @@ export type Key = {
valid_until: Date;
};

@tracedClass({ type: 'repository', className: 'KeyRepository' })
@singleton()
export class KeyRepository {
constructor(
Expand Down
4 changes: 3 additions & 1 deletion packages/federation-sdk/src/repositories/lock.repository.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import { Collection } from 'mongodb';
import type { Collection } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

export type Lock = {
roomId: string;
instanceId: string;
lockedAt: Date;
};

@tracedClass({ type: 'repository', className: 'LockRepository' })
@singleton()
export class LockRepository {
constructor(
Expand Down
4 changes: 3 additions & 1 deletion packages/federation-sdk/src/repositories/room.repository.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { EventBase } from '@rocket.chat/federation-core';
import type { EventID } from '@rocket.chat/federation-room';
import { Collection } from 'mongodb';
import type { Collection } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

export type Room = {
_id: string;
Expand All @@ -16,6 +17,7 @@ export type Room = {
};
};

@tracedClass({ type: 'repository', className: 'RoomRepository' })
@singleton()
export class RoomRepository {
constructor(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Collection } from 'mongodb';
import type { Collection } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

export type Server = {
name: string;
Expand All @@ -11,6 +12,7 @@ export type Server = {
};
};

@tracedClass({ type: 'repository', className: 'ServerRepository' })
@singleton()
export class ServerRepository {
constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
} from '@rocket.chat/federation-room';
import { type Collection, ObjectId } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

export type StateGraphStore = {
_id: StateID;
Expand All @@ -25,6 +26,7 @@ export type StateGraphStore = {
partial: boolean;
};

@tracedClass({ type: 'repository', className: 'StateGraphRepository' })
@singleton()
export class StateGraphRepository {
constructor(
Expand Down
6 changes: 4 additions & 2 deletions packages/federation-sdk/src/repositories/upload.repository.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { RoomID } from '@rocket.chat/federation-room';
import { Collection } from 'mongodb';
import type { RoomID } from '@rocket.chat/federation-room';
import type { Collection } from 'mongodb';
import { inject, singleton } from 'tsyringe';
import { tracedClass } from '../utils/tracing';

export type Upload = {
rid: string;
Expand All @@ -12,6 +13,7 @@ export type Upload = {
};
};

@tracedClass({ type: 'repository', className: 'UploadRepository' })
@singleton()
export class UploadRepository {
constructor(
Expand Down
13 changes: 12 additions & 1 deletion packages/federation-sdk/src/services/edu.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import {
createTypingEDU,
} from '@rocket.chat/federation-core';
import { createLogger } from '@rocket.chat/federation-core';
import { RoomID } from '@rocket.chat/federation-room';
import { type RoomID } from '@rocket.chat/federation-room';
import { singleton } from 'tsyringe';
import { traced, tracedClass } from '../utils/tracing';
import { ConfigService } from './config.service';
import { FederationService } from './federation.service';
import { StateService } from './state.service';

@tracedClass({ type: 'service', className: 'EduService' })
@singleton()
export class EduService {
private readonly logger = createLogger('EduService');
Expand All @@ -20,6 +22,11 @@ export class EduService {
private readonly stateService: StateService,
) {}

@traced((roomId: RoomID, userId: string, typing: boolean) => ({
roomId,
userId,
typing,
}))
async sendTypingNotification(
roomId: RoomID,
userId: string,
Expand Down Expand Up @@ -50,6 +57,10 @@ export class EduService {
}
}

@traced((presenceUpdates: PresenceUpdate[], roomIds: RoomID[]) => ({
presenceUpdateCount: presenceUpdates?.length,
roomCount: roomIds?.length,
}))
async sendPresenceUpdateToRooms(
presenceUpdates: PresenceUpdate[],
roomIds: RoomID[],
Expand Down
Loading