snapshot of https://github.com/RocketChat/Rocket.Chat.git (develop, 2026-09-16; blobs > 131072B omitted)
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
Some checks failed
Create issues from TODOs / todos (push) Failing after 3s
Close inactive issues / close-issues (push) Has been cancelled
Deploy GitHub Pages / deploy-preview (push) Has been cancelled
CI / ⚙️ Variables Setup (push) Has been cancelled
CI / ⚙️ Test Guard (push) Has been cancelled
CI / 🚀 Notify external services - draft (push) Has been cancelled
CI / 📦 Build Packages (push) Has been cancelled
CI / 📦 Meteor Build (coverage) (push) Has been cancelled
CI / 📦 Meteor Build (production) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [account-service presence-service omnichannel-transcript-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [authorization-service queue-worker-service ddp-streamer-service], fips) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Build Docker (amd64, [rocketchat], fips) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [account-service presence-service omnichannel-transcript-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [authorization-service queue-worker-service ddp-streamer-service], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], ${{ (github.event_name != 'release' && github.ref != 'refs/heads/develop') && 'coverage' || 'production' }}) (push) Has been cancelled
CI / 🚢 Build Docker (arm64, [rocketchat], coverage) (push) Has been cancelled
CI / 🚢 Publish Docker Images (ghcr.io) (push) Has been cancelled
CI / 📦 Track Image Sizes (push) Has been cancelled
CI / 🔎 Code Check - Action Lint (push) Has been cancelled
CI / 🔎 Code Check (push) Has been cancelled
CI / 🔨 Test Storybook (push) Has been cancelled
CI / 🔨 Test Unit (push) Has been cancelled
CI / 🔨 Test API (CE) (push) Has been cancelled
CI / 🔨 Test API Livechat (CE) (push) Has been cancelled
CI / 🔨 Test UI (CE) (push) Has been cancelled
CI / 🔨 Test API (EE) (push) Has been cancelled
CI / 🔨 Test API Livechat (EE) (push) Has been cancelled
CI / 🔨 Test API Apps (deno-runtime - EE) (push) Has been cancelled
CI / 🔨 Test UI (EE) (push) Has been cancelled
CI / 🔨 Test API (FIPS) (push) Has been cancelled
CI / 🔨 Test API Livechat (FIPS) (push) Has been cancelled
CI / 🔨 Test UI (FIPS) (push) Has been cancelled
CI / 🔨 Test Federation Matrix (push) Has been cancelled
CI / 📊 Report Coverage (push) Has been cancelled
CI / ✅ Tests Done (push) Has been cancelled
CI / 🚀 Publish build assets (push) Has been cancelled
CI / 🚀 Publish Docker Images (DockerHub) (push) Has been cancelled
CI / 🚀 Notify external services (push) Has been cancelled
CI / Update Version Durability (push) Has been cancelled
Release / Release (push) Has been cancelled
Auto-close duplicate issues / auto-close-duplicates (push) Failing after 1s
Code scanning - action / CodeQL-Build (push) Failing after 1s
This commit is contained in:
13
packages/tracing/CHANGELOG.md
Normal file
13
packages/tracing/CHANGELOG.md
Normal file
@@ -0,0 +1,13 @@
|
||||
# @rocket.chat/tracing
|
||||
|
||||
## 0.0.2
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ([#38989](https://github.com/RocketChat/Rocket.Chat/pull/38989)) chore(eslint): Upgrades ESLint and its configuration
|
||||
|
||||
## 0.0.2-rc.0
|
||||
|
||||
### Patch Changes
|
||||
|
||||
- ([#38989](https://github.com/RocketChat/Rocket.Chat/pull/38989)) chore(eslint): Upgrades ESLint and its configuration
|
||||
33
packages/tracing/package.json
Normal file
33
packages/tracing/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@rocket.chat/tracing",
|
||||
"version": "0.0.2",
|
||||
"private": true,
|
||||
"main": "./dist/index.js",
|
||||
"typings": "./dist/index.d.ts",
|
||||
"files": [
|
||||
"/dist"
|
||||
],
|
||||
"scripts": {
|
||||
"build": "rm -rf dist && tsc",
|
||||
"dev": "tsc --watch --preserveWatchOutput",
|
||||
"lint": "eslint .",
|
||||
"lint:fix": "eslint --fix .",
|
||||
"testunit": "jest --passWithNoTests"
|
||||
},
|
||||
"dependencies": {
|
||||
"@opentelemetry/api": "^1.9.1",
|
||||
"@opentelemetry/exporter-trace-otlp-grpc": "^0.220.0",
|
||||
"@opentelemetry/sdk-node": "^0.220.0",
|
||||
"@opentelemetry/sdk-trace-base": "^2.7.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jest": "~30.0.0",
|
||||
"eslint": "~9.39.5",
|
||||
"jest": "~30.2.0",
|
||||
"ts-jest": "~29.4.12",
|
||||
"typescript": "~5.9.3"
|
||||
},
|
||||
"volta": {
|
||||
"extends": "../../package.json"
|
||||
}
|
||||
}
|
||||
110
packages/tracing/src/index.ts
Normal file
110
packages/tracing/src/index.ts
Normal file
@@ -0,0 +1,110 @@
|
||||
import { context, propagation, SpanStatusCode, trace } from '@opentelemetry/api';
|
||||
import type { Span, SpanOptions, Tracer } from '@opentelemetry/api';
|
||||
import { OTLPTraceExporter } from '@opentelemetry/exporter-trace-otlp-grpc';
|
||||
import { NodeSDK } from '@opentelemetry/sdk-node';
|
||||
import { BatchSpanProcessor } from '@opentelemetry/sdk-trace-base';
|
||||
import type { MongoClient } from 'mongodb';
|
||||
|
||||
import { initDatabaseTracing } from './traceDatabaseCalls';
|
||||
|
||||
let tracer: Tracer | undefined;
|
||||
|
||||
export * from './traceInstanceMethods';
|
||||
|
||||
export function isTracingEnabled() {
|
||||
return ['yes', 'true'].includes(String(process.env.TRACING_ENABLED).toLowerCase());
|
||||
}
|
||||
|
||||
export const startTracing = ({ service, db }: { service: string; db: MongoClient }) => {
|
||||
if (!isTracingEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const exporter = new OTLPTraceExporter();
|
||||
|
||||
const sdk = new NodeSDK({
|
||||
traceExporter: exporter,
|
||||
instrumentations: [],
|
||||
serviceName: service,
|
||||
spanProcessors: [new BatchSpanProcessor(exporter)],
|
||||
});
|
||||
sdk.start();
|
||||
|
||||
tracer = trace.getTracer(service);
|
||||
|
||||
initDatabaseTracing(tracer, db);
|
||||
};
|
||||
|
||||
export function tracerSpan<F extends (span?: Span) => ReturnType<F>>(
|
||||
name: string,
|
||||
options: SpanOptions,
|
||||
fn: F,
|
||||
optl?: unknown,
|
||||
): ReturnType<F> {
|
||||
if (!isTracingEnabled()) {
|
||||
return fn();
|
||||
}
|
||||
|
||||
if (!tracer) {
|
||||
throw new Error(`Tracing is enabled but not started. You should call 'startTracing()' to fix this.`);
|
||||
}
|
||||
|
||||
const computeResult = (span: Span) => {
|
||||
try {
|
||||
const result = fn(span);
|
||||
if (result instanceof Promise) {
|
||||
result
|
||||
.catch((err) => {
|
||||
span.recordException(err);
|
||||
span.setStatus({
|
||||
code: SpanStatusCode.ERROR,
|
||||
message: err.message,
|
||||
});
|
||||
})
|
||||
.finally(() => span.end());
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
span.end();
|
||||
return result;
|
||||
} catch (err: any) {
|
||||
span.recordException(err);
|
||||
span.setStatus({
|
||||
code: SpanStatusCode.ERROR,
|
||||
message: err.message,
|
||||
});
|
||||
span.end();
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
if (optl) {
|
||||
const activeContext = propagation.extract(context.active(), optl);
|
||||
|
||||
return tracer.startActiveSpan(name, options, activeContext, computeResult);
|
||||
}
|
||||
|
||||
return tracer.startActiveSpan(name, options, computeResult);
|
||||
}
|
||||
|
||||
export function tracerActiveSpan<F extends (span?: Span) => ReturnType<F>>(
|
||||
name: string,
|
||||
options: SpanOptions,
|
||||
fn: F,
|
||||
optl?: unknown,
|
||||
): ReturnType<F> {
|
||||
const currentSpan = trace.getSpan(context.active());
|
||||
|
||||
if (process.env.LOG_UNTRACED_METHODS) {
|
||||
console.log(`No active span for ${name}`, new Error().stack);
|
||||
}
|
||||
|
||||
return currentSpan ? tracerSpan(name, options, fn, optl) : fn();
|
||||
}
|
||||
|
||||
export function injectCurrentContext() {
|
||||
const output: Record<string, string> = {};
|
||||
propagation.inject(context.active(), output);
|
||||
return output;
|
||||
}
|
||||
68
packages/tracing/src/traceDatabaseCalls.ts
Normal file
68
packages/tracing/src/traceDatabaseCalls.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import type { Tracer } from '@opentelemetry/api';
|
||||
import { trace, context, SpanStatusCode } from '@opentelemetry/api';
|
||||
import type { MongoClient } from 'mongodb';
|
||||
|
||||
export const initDatabaseTracing = (tracer: Tracer, client: MongoClient) => {
|
||||
const DurationStart = new Map();
|
||||
|
||||
client.on('commandStarted', (event) => {
|
||||
const collection = event.command[event.commandName];
|
||||
|
||||
const currentSpan = trace.getSpan(context.active());
|
||||
if (currentSpan) {
|
||||
const span = tracer.startSpan(`mongodb ${collection}.${event.commandName}`, {
|
||||
attributes: {
|
||||
'db.connection_string': event.address,
|
||||
'db.mongodb.collection': collection,
|
||||
'db.name': event.databaseName,
|
||||
'db.operation': event.commandName,
|
||||
'db.statement': JSON.stringify(
|
||||
event.command,
|
||||
(_key, value) => {
|
||||
// Support for tracing MongoDB commands with RegExp
|
||||
if (value instanceof RegExp) {
|
||||
return value.toString();
|
||||
}
|
||||
return value;
|
||||
},
|
||||
2,
|
||||
),
|
||||
'db.system': 'mongodb',
|
||||
// net.peer.name
|
||||
// net.peer.port
|
||||
},
|
||||
});
|
||||
|
||||
DurationStart.set(event.requestId, { event, span });
|
||||
}
|
||||
});
|
||||
|
||||
client.on('commandSucceeded', (event) => {
|
||||
if (!DurationStart.has(event.requestId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { span } = DurationStart.get(event.requestId);
|
||||
DurationStart.delete(event.requestId);
|
||||
|
||||
span.end();
|
||||
});
|
||||
|
||||
client.on('commandFailed', (event) => {
|
||||
if (!DurationStart.has(event.requestId)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const { span } = DurationStart.get(event.requestId);
|
||||
|
||||
DurationStart.delete(event.requestId);
|
||||
|
||||
span.recordException(event.failure);
|
||||
span.setStatus({
|
||||
code: SpanStatusCode.ERROR,
|
||||
message: event.failure.message,
|
||||
});
|
||||
|
||||
span.end();
|
||||
});
|
||||
};
|
||||
44
packages/tracing/src/traceInstanceMethods.ts
Normal file
44
packages/tracing/src/traceInstanceMethods.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import { tracerActiveSpan } from '.';
|
||||
|
||||
const getArguments = (args: any[]): any[] => {
|
||||
return args.map((arg) => {
|
||||
if (typeof arg === 'object' && arg != null && 'session' in arg) {
|
||||
return '[mongo options with session]';
|
||||
}
|
||||
return arg;
|
||||
});
|
||||
};
|
||||
|
||||
export function traceInstanceMethods<T extends object>(instance: T, ignoreMethods: string[] = []): T {
|
||||
const className = instance.constructor.name;
|
||||
|
||||
return new Proxy(instance, {
|
||||
get(target: Record<string, any>, prop: string): any {
|
||||
if (typeof target[prop] === 'function' && !ignoreMethods.includes(prop)) {
|
||||
return new Proxy(target[prop], {
|
||||
apply: (target, thisArg, argumentsList): any => {
|
||||
if (['doNotMixInclusionAndExclusionFields', 'ensureDefaultFields'].includes(prop)) {
|
||||
return Reflect.apply(target, thisArg, argumentsList);
|
||||
}
|
||||
|
||||
return tracerActiveSpan(
|
||||
`model ${className}.${prop}`,
|
||||
{
|
||||
attributes: {
|
||||
model: className,
|
||||
method: prop,
|
||||
parameters: getArguments(argumentsList),
|
||||
},
|
||||
},
|
||||
() => {
|
||||
return Reflect.apply(target, thisArg, argumentsList);
|
||||
},
|
||||
);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
return Reflect.get(target, prop);
|
||||
},
|
||||
}) as T;
|
||||
}
|
||||
9
packages/tracing/tsconfig.json
Normal file
9
packages/tracing/tsconfig.json
Normal file
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"extends": "@rocket.chat/tsconfig/server.json",
|
||||
"compilerOptions": {
|
||||
"declaration": true,
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist"
|
||||
},
|
||||
"include": ["./src/**/*"]
|
||||
}
|
||||
Reference in New Issue
Block a user