feat(medusa,medusa-telemetry): Add telemetry on feature flags (#2017)
This commit is contained in:
1 parent
aaebb38eae
commit
900260c5b9
5 files changed
+54
-28
No files matched your search
@@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
"medusa-telemetry": patch
|
||||||
|
"@medusajs/medusa": patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Adds enabled features flags to tracking event in `medusa-telemetry`
|
||||||
@@ -17,4 +17,8 @@ export const setTelemetryEnabled = (enabled = true) => {
|
|||||||
telemeter.setTelemetryEnabled(enabled)
|
telemeter.setTelemetryEnabled(enabled)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function trackFeatureFlag(flag) {
|
||||||
|
telemeter.trackFeatureFlag(flag)
|
||||||
|
}
|
||||||
|
|
||||||
export { default as Telemeter } from "./telemeter"
|
export { default as Telemeter } from "./telemeter"
|
||||||
@@ -1,15 +1,15 @@
|
|||||||
import os from "os"
|
|
||||||
import fs from "fs"
|
import fs from "fs"
|
||||||
import { join, sep } from "path"
|
|
||||||
import isDocker from "is-docker"
|
import isDocker from "is-docker"
|
||||||
|
import os from "os"
|
||||||
|
import { join, sep } from "path"
|
||||||
import { v4 as uuidv4 } from "uuid"
|
import { v4 as uuidv4 } from "uuid"
|
||||||
|
|
||||||
|
import Store from "./store"
|
||||||
import createFlush from "./util/create-flush"
|
import createFlush from "./util/create-flush"
|
||||||
import getTermProgram from "./util/get-term-program"
|
import getTermProgram from "./util/get-term-program"
|
||||||
|
import { getCIName, isCI } from "./util/is-ci"
|
||||||
import isTruthy from "./util/is-truthy"
|
import isTruthy from "./util/is-truthy"
|
||||||
import showAnalyticsNotification from "./util/show-notification"
|
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
|
const MEDUSA_TELEMETRY_VERBOSE = process.env.MEDUSA_TELEMETRY_VERBOSE || false
|
||||||
|
|
||||||
@@ -24,6 +24,8 @@ class Telemeter {
|
|||||||
|
|
||||||
this.queueSize_ = this.store_.getQueueSize()
|
this.queueSize_ = this.store_.getQueueSize()
|
||||||
this.queueCount_ = this.store_.getQueueCount()
|
this.queueCount_ = this.store_.getQueueCount()
|
||||||
|
|
||||||
|
this.featureFlags_ = new Set()
|
||||||
}
|
}
|
||||||
|
|
||||||
getMachineId() {
|
getMachineId() {
|
||||||
@@ -130,6 +132,7 @@ class Telemeter {
|
|||||||
os_info: this.getOsInfo(),
|
os_info: this.getOsInfo(),
|
||||||
medusa_version: this.getMedusaVersion(),
|
medusa_version: this.getMedusaVersion(),
|
||||||
cli_version: this.getCliVersion(),
|
cli_version: this.getCliVersion(),
|
||||||
|
feature_flags: Array.from(this.featureFlags_),
|
||||||
}
|
}
|
||||||
|
|
||||||
this.store_.addEvent(event)
|
this.store_.addEvent(event)
|
||||||
@@ -152,6 +155,12 @@ class Telemeter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trackFeatureFlag(flag) {
|
||||||
|
if (flag) {
|
||||||
|
this.featureFlags_.add(flag)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default Telemeter
|
export default Telemeter
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
import path from "path"
|
|
||||||
import glob from "glob"
|
import glob from "glob"
|
||||||
|
import path from "path"
|
||||||
|
|
||||||
|
import { trackFeatureFlag } from "medusa-telemetry"
|
||||||
import { FlagSettings } from "../../types/feature-flags"
|
import { FlagSettings } from "../../types/feature-flags"
|
||||||
import { FlagRouter } from "../../utils/flag-router"
|
|
||||||
import { Logger } from "../../types/global"
|
import { Logger } from "../../types/global"
|
||||||
|
import { FlagRouter } from "../../utils/flag-router"
|
||||||
|
|
||||||
const isTruthy = (val: string | boolean | undefined): boolean => {
|
const isTruthy = (val: string | boolean | undefined): boolean => {
|
||||||
if (typeof val === "string") {
|
if (typeof val === "string") {
|
||||||
@@ -62,6 +63,10 @@ export default (
|
|||||||
default:
|
default:
|
||||||
flagConfig[flagSettings.key] = flagSettings.default_val
|
flagConfig[flagSettings.key] = flagSettings.default_val
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (flagConfig[flagSettings.key]) {
|
||||||
|
trackFeatureFlag(flagSettings.key)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new FlagRouter(flagConfig)
|
return new FlagRouter(flagConfig)
|
||||||
|
|||||||
@@ -1,24 +1,3 @@
|
|||||||
import loadConfig from "./config"
|
|
||||||
import "reflect-metadata"
|
|
||||||
import Logger from "./logger"
|
|
||||||
import apiLoader from "./api"
|
|
||||||
import featureFlagsLoader from "./feature-flags"
|
|
||||||
import databaseLoader from "./database"
|
|
||||||
import defaultsLoader from "./defaults"
|
|
||||||
import expressLoader from "./express"
|
|
||||||
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 {
|
import {
|
||||||
asFunction,
|
asFunction,
|
||||||
asValue,
|
asValue,
|
||||||
@@ -26,8 +5,29 @@ import {
|
|||||||
createContainer,
|
createContainer,
|
||||||
Resolver,
|
Resolver,
|
||||||
} from "awilix"
|
} from "awilix"
|
||||||
|
import { ClassOrFunctionReturning } from "awilix/lib/container"
|
||||||
|
import { Express, NextFunction, Request, Response } from "express"
|
||||||
import { track } from "medusa-telemetry"
|
import { track } from "medusa-telemetry"
|
||||||
|
import "reflect-metadata"
|
||||||
|
import requestIp from "request-ip"
|
||||||
|
import { Connection, getManager } from "typeorm"
|
||||||
import { MedusaContainer } from "../types/global"
|
import { MedusaContainer } from "../types/global"
|
||||||
|
import apiLoader from "./api"
|
||||||
|
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 searchIndexLoader from "./search-index"
|
||||||
|
import servicesLoader from "./services"
|
||||||
|
import strategiesLoader from "./strategies"
|
||||||
|
import subscribersLoader from "./subscribers"
|
||||||
|
|
||||||
type Options = {
|
type Options = {
|
||||||
directory: string
|
directory: string
|
||||||
@@ -82,6 +82,7 @@ export default async ({
|
|||||||
})
|
})
|
||||||
|
|
||||||
const featureFlagRouter = featureFlagsLoader(configModule, Logger)
|
const featureFlagRouter = featureFlagsLoader(configModule, Logger)
|
||||||
|
track("FEATURE_FLAGS_LOADED")
|
||||||
|
|
||||||
container.register({
|
container.register({
|
||||||
logger: asValue(Logger),
|
logger: asValue(Logger),
|
||||||
@@ -179,7 +180,8 @@ export default async ({
|
|||||||
const searchActivity = Logger.activity("Initializing search engine indexing")
|
const searchActivity = Logger.activity("Initializing search engine indexing")
|
||||||
track("SEARCH_ENGINE_INDEXING_STARTED")
|
track("SEARCH_ENGINE_INDEXING_STARTED")
|
||||||
await searchIndexLoader({ container })
|
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 })
|
track("SEARCH_ENGINE_INDEXING_COMPLETED", { duration: searchAct.duration })
|
||||||
|
|
||||||
return { container, dbConnection, app: expressApp }
|
return { container, dbConnection, app: expressApp }
|
||||||
|
|||||||
Reference in new issue
Block a user