From 0b683876f89302fd8a1a15c38883732697c5b611 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 19 Dec 2023 16:25:45 +0000 Subject: [PATCH 1/2] Set app_id, user_id, and tenant_id as baggage items on spans. --- packages/server/src/middleware/currentapp.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/packages/server/src/middleware/currentapp.ts b/packages/server/src/middleware/currentapp.ts index 4b11b933af..c1e9dfff15 100644 --- a/packages/server/src/middleware/currentapp.ts +++ b/packages/server/src/middleware/currentapp.ts @@ -23,7 +23,7 @@ export default async (ctx: UserCtx, next: any) => { if (requestAppId) { const span = tracer.scope().active() - span?.addTags({ app_id: requestAppId }) + span?.setBaggageItem("app_id", requestAppId) } // deny access to application preview @@ -76,6 +76,14 @@ export default async (ctx: UserCtx, next: any) => { return next() } + if (ctx.user) { + const span = tracer.scope().active() + if (ctx.user._id) { + span?.setBaggageItem("user_id", ctx.user._id) + } + span?.setBaggageItem("tenant_id", ctx.user.tenantId) + } + const userId = ctx.user ? generateUserMetadataID(ctx.user._id!) : undefined // if the user is not in the right tenant then make sure to wipe their cookie From 056214c9843cb6a9d81404f478a0a058fe7519d6 Mon Sep 17 00:00:00 2001 From: Sam Rose Date: Tue, 19 Dec 2023 16:26:09 +0000 Subject: [PATCH 2/2] Use camelCase for tags. --- packages/server/src/middleware/currentapp.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/server/src/middleware/currentapp.ts b/packages/server/src/middleware/currentapp.ts index c1e9dfff15..818c0ab171 100644 --- a/packages/server/src/middleware/currentapp.ts +++ b/packages/server/src/middleware/currentapp.ts @@ -23,7 +23,7 @@ export default async (ctx: UserCtx, next: any) => { if (requestAppId) { const span = tracer.scope().active() - span?.setBaggageItem("app_id", requestAppId) + span?.setBaggageItem("appId", requestAppId) } // deny access to application preview @@ -79,9 +79,9 @@ export default async (ctx: UserCtx, next: any) => { if (ctx.user) { const span = tracer.scope().active() if (ctx.user._id) { - span?.setBaggageItem("user_id", ctx.user._id) + span?.setBaggageItem("userId", ctx.user._id) } - span?.setBaggageItem("tenant_id", ctx.user.tenantId) + span?.setBaggageItem("tenantId", ctx.user.tenantId) } const userId = ctx.user ? generateUserMetadataID(ctx.user._id!) : undefined