From 47c9c43a875a81aa357ebf3c741f256c317c5cfd Mon Sep 17 00:00:00 2001 From: Phillip Ho Date: Sat, 1 Mar 2025 10:53:56 +0800 Subject: [PATCH] [service-utils] trim project ID prefix (#6382) --- .changeset/brown-onions-tickle.md | 5 +++++ packages/service-utils/src/node/usageV2.ts | 11 +++++++++-- 2 files changed, 14 insertions(+), 2 deletions(-) create mode 100644 .changeset/brown-onions-tickle.md diff --git a/.changeset/brown-onions-tickle.md b/.changeset/brown-onions-tickle.md new file mode 100644 index 00000000000..281087a57cf --- /dev/null +++ b/.changeset/brown-onions-tickle.md @@ -0,0 +1,5 @@ +--- +"@thirdweb-dev/service-utils": patch +--- + +[service-utils] trim project ID prefix diff --git a/packages/service-utils/src/node/usageV2.ts b/packages/service-utils/src/node/usageV2.ts index 3a37a99b538..ed2d158c6b1 100644 --- a/packages/service-utils/src/node/usageV2.ts +++ b/packages/service-utils/src/node/usageV2.ts @@ -6,6 +6,9 @@ import { } from "../core/usageV2.js"; import { KafkaProducer } from "./kafka.js"; +const TEAM_ID_PREFIX = "team_"; +const PROJECT_ID_PREFIX = "prj_"; + /** * Creates a UsageV2Producer which opens a persistent TCP connection. * This class is thread-safe so your service should re-use one instance. @@ -65,9 +68,13 @@ export class UsageV2Producer { // Default to now. created_at: event.created_at ?? new Date(), // Remove the "team_" prefix, if any. - team_id: event.team_id.startsWith("team_") - ? event.team_id.slice(5) + team_id: event.team_id.startsWith(TEAM_ID_PREFIX) + ? event.team_id.slice(TEAM_ID_PREFIX.length) : event.team_id, + // Remove the "prj_" prefix, if any. + project_id: event.project_id?.startsWith(PROJECT_ID_PREFIX) + ? event.project_id.slice(PROJECT_ID_PREFIX.length) + : event.project_id, })); await this.kafkaProducer.send(this.topic, parsedEvents); }