Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(medusa,medusa-telemetry): Add telemetry on feature flags #2017

Merged
merged 4 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .changeset/eighty-onions-share.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"medusa-telemetry": patch
"@medusajs/medusa": patch
---

Adds enabled features flags to tracking event in `medusa-telemetry`
4 changes: 4 additions & 0 deletions packages/medusa-telemetry/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
17 changes: 13 additions & 4 deletions packages/medusa-telemetry/src/telemeter.js
Original file line number Diff line number Diff line change
@@ -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

Expand All @@ -24,6 +24,8 @@ class Telemeter {

this.queueSize_ = this.store_.getQueueSize()
this.queueCount_ = this.store_.getQueueCount()

this.featureFlags_ = new Set()
}

getMachineId() {
Expand Down Expand Up @@ -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)
Expand All @@ -152,6 +155,12 @@ class Telemeter {
}
}
}

trackFeatureFlag(flag) {
if (flag) {
this.featureFlags_.add(flag)
}
}
}

export default Telemeter
9 changes: 7 additions & 2 deletions packages/medusa/src/loaders/feature-flags/index.ts
Original file line number Diff line number Diff line change
@@ -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") {
Expand Down Expand Up @@ -62,6 +63,10 @@ export default (
default:
flagConfig[flagSettings.key] = flagSettings.default_val
}

if (flagConfig[flagSettings.key]) {
trackFeatureFlag(flagSettings.key)
}
}

return new FlagRouter(flagConfig)
Expand Down