Skip to content

Commit ef0db55

Browse files
authored
qfix: Update traces send to opentelemetry (#9728)
+ Minimize amount of data send to traces. + Join WebSocket and RPC calls into one flat hierarchy. Signed-off-by: Andrey Sobolev <[email protected]>
1 parent 2659693 commit ef0db55

File tree

13 files changed

+389
-266
lines changed

13 files changed

+389
-266
lines changed

pods/fulltext/src/server.ts

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,23 @@ export async function startIndexer (
133133
const token = request.token ?? req.headers.authorization?.split(' ')[1]
134134
const decoded = decodeToken(token) // Just to be safe
135135

136-
ctx.info('search', { classes: request._classes, query: request.query, workspace: decoded.workspace })
137-
await ctx.with('search', {}, async (ctx) => {
138-
const docs = await ctx.with('search', { workspace: decoded.workspace }, (ctx) =>
139-
manager.fulltextAdapter.search(ctx, decoded.workspace, request._classes, request.query, request.fullTextLimit)
140-
)
141-
req.body = docs
142-
})
136+
await ctx.with(
137+
'search',
138+
{},
139+
async (ctx) => {
140+
req.body = await manager.fulltextAdapter.search(
141+
ctx,
142+
decoded.workspace,
143+
request._classes,
144+
request.query,
145+
request.fullTextLimit
146+
)
147+
},
148+
{
149+
workspace: decoded.workspace,
150+
classes: request._classes
151+
}
152+
)
143153
} catch (err: any) {
144154
Analytics.handleError(err)
145155
console.error(err)
@@ -153,20 +163,24 @@ export async function startIndexer (
153163
const request = req.request.body as FulltextSearch
154164
const token = request.token ?? req.headers.authorization?.split(' ')[1]
155165
const decoded = decodeToken(token) // Just to be safe
156-
ctx.info('fulltext-search', { ...request.query, workspace: decoded.workspace })
157-
await ctx.with('full-text-search', {}, async (ctx) => {
158-
const result = await ctx.with('searchFulltext', {}, (ctx) =>
159-
searchFulltext(
166+
await ctx.with(
167+
'full-text-search',
168+
{},
169+
async (ctx) => {
170+
const result = await searchFulltext(
160171
ctx,
161172
decoded.workspace,
162173
manager.sysHierarchy,
163174
manager.fulltextAdapter,
164175
request.query,
165176
request.options
166177
)
167-
)
168-
req.body = result
169-
})
178+
req.body = result
179+
},
180+
{
181+
workspace: decoded.workspace
182+
}
183+
)
170184
} catch (err: any) {
171185
Analytics.handleError(err)
172186
console.error(err)

pods/server/src/rpc.ts

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
139139
async function withSession (
140140
req: Request,
141141
res: ExpressResponse,
142+
method: string,
142143
operation: (
143144
ctx: ClientSessionCtx,
144145
session: Session,
@@ -183,9 +184,15 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
183184
}
184185

185186
const rpc = transactorRpc
186-
const rateLimit = await sessions.handleRPC(rpc.context, rpc.session, rpc.client, async (ctx, rateLimit) => {
187-
await operation(ctx, rpc.session, rateLimit, token)
188-
})
187+
const rateLimit = await sessions.handleRPC(
188+
rpc.context,
189+
rpc.session,
190+
method,
191+
rpc.client,
192+
async (ctx, rateLimit) => {
193+
await operation(ctx, rpc.session, rateLimit, token)
194+
}
195+
)
189196
if (rateLimit !== undefined) {
190197
const { remaining, limit, reset, retryAfter } = rateLimit
191198
const retryHeaders: OutgoingHttpHeaders = {
@@ -212,7 +219,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
212219
}
213220

214221
app.get('/api/v1/ping/:workspaceId', (req, res) => {
215-
void withSession(req, res, async (ctx, session, rateLimit) => {
222+
void withSession(req, res, 'ping', async (ctx, session, rateLimit) => {
216223
await session.ping(ctx)
217224
await sendJson(
218225
req,
@@ -228,7 +235,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
228235
})
229236

230237
app.get('/api/v1/find-all/:workspaceId', (req, res) => {
231-
void withSession(req, res, async (ctx, session, rateLimit) => {
238+
void withSession(req, res, 'findAll', async (ctx, session, rateLimit) => {
232239
const _class = req.query.class as Ref<Class<Doc>>
233240
const query = req.query.query !== undefined ? JSON.parse(req.query.query as string) : {}
234241
const options = req.query.options !== undefined ? JSON.parse(req.query.options as string) : {}
@@ -242,7 +249,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
242249
})
243250

244251
app.post('/api/v1/find-all/:workspaceId', (req, res) => {
245-
void withSession(req, res, async (ctx, session, rateLimit) => {
252+
void withSession(req, res, 'findAll', async (ctx, session, rateLimit) => {
246253
const { _class, query, options }: any = (await retrieveJson(req)) ?? {}
247254

248255
const result = await session.findAllRaw(ctx, _class, query, options)
@@ -251,7 +258,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
251258
})
252259

253260
app.post('/api/v1/tx/:workspaceId', (req, res) => {
254-
void withSession(req, res, async (ctx, session, rateLimit) => {
261+
void withSession(req, res, 'tx', async (ctx, session, rateLimit) => {
255262
const tx: any = (await retrieveJson(req)) ?? {}
256263

257264
if (tx._class === core.class.TxDomainEvent) {
@@ -271,7 +278,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
271278
* @deprecated Use /api/v1/tx/:workspaceIdd instead
272279
*/
273280
app.post('/api/v1/event/:workspaceId', (req, res) => {
274-
void withSession(req, res, async (ctx, session) => {
281+
void withSession(req, res, 'domainRequest', async (ctx, session) => {
275282
const event: any = (await retrieveJson(req)) ?? {}
276283

277284
const { result } = await session.domainRequestRaw(ctx, COMMUNICATION_DOMAIN, {
@@ -282,14 +289,14 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
282289
})
283290

284291
app.get('/api/v1/account/:workspaceId', (req, res) => {
285-
void withSession(req, res, async (ctx, session, rateLimit) => {
292+
void withSession(req, res, 'account', async (ctx, session, rateLimit) => {
286293
const result = session.getRawAccount()
287294
await sendJson(req, res, result, rateLimitToHeaders(rateLimit))
288295
})
289296
})
290297

291298
app.get('/api/v1/load-model/:workspaceId', (req, res) => {
292-
void withSession(req, res, async (ctx, session, rateLimit) => {
299+
void withSession(req, res, 'loadModel', async (ctx, session, rateLimit) => {
293300
const lastModelTx = parseInt((req.query.lastModelTx as string) ?? '0')
294301
const lastHash = req.query.lastHash as string
295302
const result = await session.loadModelRaw(ctx, lastModelTx, lastHash)
@@ -322,7 +329,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
322329
})
323330

324331
app.get('/api/v1/search-fulltext/:workspaceId', (req, res) => {
325-
void withSession(req, res, async (ctx, session, rateLimit) => {
332+
void withSession(req, res, 'searchFulltext', async (ctx, session, rateLimit) => {
326333
const query: SearchQuery = {
327334
query: req.query.query as string,
328335
classes: req.query.classes !== undefined ? JSON.parse(req.query.classes as string) : undefined,
@@ -337,7 +344,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
337344
})
338345

339346
app.get('/api/v1/request/:domain/:operation/:workspaceId', (req, res) => {
340-
void withSession(req, res, async (ctx, session) => {
347+
void withSession(req, res, 'domainRequest', async (ctx, session) => {
341348
const domain = req.params.domain as OperationDomain
342349
const operation = req.params.operation
343350

@@ -351,7 +358,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
351358
})
352359

353360
app.post('/api/v1/request/:domain/:workspaceId', (req, res) => {
354-
void withSession(req, res, async (ctx, session) => {
361+
void withSession(req, res, 'domainRequest', async (ctx, session) => {
355362
const domain = req.params.domain as OperationDomain
356363
const params = retrieveJson(req)
357364
const { result } = await session.domainRequestRaw(ctx, domain, params)
@@ -360,7 +367,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
360367
})
361368

362369
app.post('/api/v1/ensure-person/:workspaceId', (req, res) => {
363-
void withSession(req, res, async (ctx, session, rateLimit, token) => {
370+
void withSession(req, res, 'ensurePerson', async (ctx, session, rateLimit, token) => {
364371
const { socialType, socialValue, firstName, lastName } = (await retrieveJson(req)) ?? {}
365372
const accountClient = getAccountClient(token)
366373

@@ -438,7 +445,7 @@ export function registerRPC (app: Express, sessions: SessionManager, ctx: Measur
438445

439446
// To use in non-js (rust) clients that can't link to @hcengineering/core
440447
app.get('/api/v1/generate-id/:workspaceId', (req, res) => {
441-
void withSession(req, res, async (ctx, session, rateLimit) => {
448+
void withSession(req, res, 'generateId', async (ctx, session, rateLimit) => {
442449
const result = { id: generateId() }
443450
await sendJson(req, res, result, rateLimitToHeaders(rateLimit))
444451
})

pods/server/src/server_http.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,7 @@ export function startHttpServer (
357357
})
358358
res.end(JSON.stringify({ success: true }))
359359
},
360-
{ file: name, contentType, workspace: wsIds.uuid }
360+
{ contentType, workspace: wsIds.uuid }
361361
)
362362
} catch (err: any) {
363363
Analytics.handleError(err)

server/account-service/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,7 @@ export function serveAccount (measureCtx: MeasureContext, brandings: BrandingMap
429429
ctx.res.writeHead(200, KEEP_ALIVE_HEADERS)
430430
ctx.res.end(body)
431431
},
432-
{ ...request }
432+
{ method: request.method }
433433
)
434434
})
435435

server/collaborator/src/extensions/storage.ts

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -169,9 +169,17 @@ export class StorageExtension implements Extension {
169169
const { ctx, adapter } = this.configuration
170170

171171
try {
172-
return await ctx.with('load-document', {}, (ctx) => {
173-
return adapter.loadDocument(ctx, documentName, context)
174-
})
172+
return await ctx.with(
173+
'load-document',
174+
{},
175+
(ctx) => {
176+
return adapter.loadDocument(ctx, documentName, context)
177+
},
178+
{
179+
workspace: context.wsIds.uuid,
180+
documentName
181+
}
182+
)
175183
} catch (err: any) {
176184
Analytics.handleError(err)
177185
ctx.error('failed to load document', { documentName, error: err })
@@ -220,11 +228,18 @@ export class StorageExtension implements Extension {
220228
const now = Date.now()
221229

222230
try {
223-
const currMarkup = await ctx.with('save-document', {}, (ctx) =>
224-
adapter.saveDocument(ctx, documentName, document, context, {
225-
prev: () => this.markups.get(documentName) ?? {},
226-
curr: () => this.configuration.transformer.fromYdoc(document)
227-
})
231+
const currMarkup = await ctx.with(
232+
'save-document',
233+
{},
234+
(ctx) =>
235+
adapter.saveDocument(ctx, documentName, document, context, {
236+
prev: () => this.markups.get(documentName) ?? {},
237+
curr: () => this.configuration.transformer.fromYdoc(document)
238+
}),
239+
{
240+
workspace: context.wsIds.uuid,
241+
documentName
242+
}
228243
)
229244

230245
this.markups.set(documentName, currMarkup ?? {})

0 commit comments

Comments
 (0)