diff --git a/.changeset/eighty-onions-share.md b/.changeset/eighty-onions-share.md new file mode 100644 index 0000000000000..373a03fc561f1 --- /dev/null +++ b/.changeset/eighty-onions-share.md @@ -0,0 +1,6 @@ +--- +"medusa-telemetry": patch +"@medusajs/medusa": patch +--- + +Adds enabled features flags to tracking event in `medusa-telemetry` diff --git a/packages/medusa-telemetry/src/index.js b/packages/medusa-telemetry/src/index.js index 2d4e355849071..761137885ad72 100644 --- a/packages/medusa-telemetry/src/index.js +++ b/packages/medusa-telemetry/src/index.js @@ -17,4 +17,8 @@ export const setTelemetryEnabled = (enabled = true) => { telemeter.setTelemetryEnabled(enabled) } +export function trackFeatureFlag(flag) { + telemeter.trackFeatureFlag(flag) +} + export { default as Telemeter } from "./telemeter" diff --git a/packages/medusa-telemetry/src/telemeter.js b/packages/medusa-telemetry/src/telemeter.js index 28dd796bb91e0..8da93594ac935 100644 --- a/packages/medusa-telemetry/src/telemeter.js +++ b/packages/medusa-telemetry/src/telemeter.js @@ -1,15 +1,15 @@ -import os from "os" import fs from "fs" -import { join, sep } from "path" import isDocker from "is-docker" +import os from "os" +import { join, sep } from "path" import { v4 as uuidv4 } from "uuid" +import Store from "./store" import createFlush from "./util/create-flush" import getTermProgram from "./util/get-term-program" +import { getCIName, isCI } from "./util/is-ci" import isTruthy from "./util/is-truthy" import showAnalyticsNotification from "./util/show-notification" -import { isCI, getCIName } from "./util/is-ci" -import Store from "./store" const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false @@ -24,6 +24,8 @@ class Telemeter { this.queueSize_ = this.store_.getQueueSize() this.queueCount_ = this.store_.getQueueCount() + + this.featureFlags_ = new Set() } getMachineId() { @@ -130,6 +132,7 @@ class Telemeter { os_info: this.getOsInfo(), medusa_version: this.getMedusaVersion(), cli_version: this.getCliVersion(), + feature_flags: Array.from(this.featureFlags_), } this.store_.addEvent(event) @@ -152,6 +155,12 @@ class Telemeter { } } } + + trackFeatureFlag(flag) { + if (flag) { + this.featureFlags_.add(flag) + } + } } export default Telemeter diff --git a/packages/medusa/src/loaders/feature-flags/index.ts b/packages/medusa/src/loaders/feature-flags/index.ts index 368365da264a6..c76bcb4f25317 100644 --- a/packages/medusa/src/loaders/feature-flags/index.ts +++ b/packages/medusa/src/loaders/feature-flags/index.ts @@ -1,9 +1,10 @@ -import path from "path" import glob from "glob" +import path from "path" +import { trackFeatureFlag } from "medusa-telemetry" import { FlagSettings } from "../../types/feature-flags" -import { FlagRouter } from "../../utils/flag-router" import { Logger } from "../../types/global" +import { FlagRouter } from "../../utils/flag-router" const isTruthy = (val: string | boolean | undefined): boolean => { if (typeof val === "string") { @@ -62,6 +63,10 @@ export default ( default: flagConfig[flagSettings.key] = flagSettings.default_val } + + if (flagConfig[flagSettings.key]) { + trackFeatureFlag(flagSettings.key) + } } return new FlagRouter(flagConfig) diff --git a/packages/medusa/src/loaders/index.ts b/packages/medusa/src/loaders/index.ts index 95aea94980e9c..35d0bd2389724 100644 --- a/packages/medusa/src/loaders/index.ts +++ b/packages/medusa/src/loaders/index.ts @@ -1,33 +1,33 @@ -import loadConfig from "./config" +import { + asFunction, + asValue, + AwilixContainer, + createContainer, + Resolver, +} from "awilix" +import { ClassOrFunctionReturning } from "awilix/lib/container" +import { Express, NextFunction, Request, Response } from "express" +import { track } from "medusa-telemetry" import "reflect-metadata" -import Logger from "./logger" +import requestIp from "request-ip" +import { Connection, getManager } from "typeorm" +import { MedusaContainer } from "../types/global" import apiLoader from "./api" -import featureFlagsLoader from "./feature-flags" +import loadConfig from "./config" import databaseLoader from "./database" import defaultsLoader from "./defaults" import expressLoader from "./express" +import featureFlagsLoader from "./feature-flags" +import Logger from "./logger" import modelsLoader from "./models" import passportLoader from "./passport" import pluginsLoader, { registerPluginModels } from "./plugins" import redisLoader from "./redis" import repositoriesLoader from "./repositories" -import requestIp from "request-ip" import searchIndexLoader from "./search-index" import servicesLoader from "./services" import strategiesLoader from "./strategies" import subscribersLoader from "./subscribers" -import { ClassOrFunctionReturning } from "awilix/lib/container" -import { Connection, getManager } from "typeorm" -import { Express, NextFunction, Request, Response } from "express" -import { - asFunction, - asValue, - AwilixContainer, - createContainer, - Resolver, -} from "awilix" -import { track } from "medusa-telemetry" -import { MedusaContainer } from "../types/global" type Options = { directory: string @@ -82,6 +82,7 @@ export default async ({ }) const featureFlagRouter = featureFlagsLoader(configModule, Logger) + track("FEATURE_FLAGS_LOADED") container.register({ logger: asValue(Logger), @@ -179,7 +180,8 @@ export default async ({ const searchActivity = Logger.activity("Initializing search engine indexing") track("SEARCH_ENGINE_INDEXING_STARTED") await searchIndexLoader({ container }) - const searchAct = Logger.success(searchActivity, "Indexing event emitted") || {} + const searchAct = + Logger.success(searchActivity, "Indexing event emitted") || {} track("SEARCH_ENGINE_INDEXING_COMPLETED", { duration: searchAct.duration }) return { container, dbConnection, app: expressApp }