Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(billing): hide unheld Logs add-ons and round scaled add-on prices (#109162)

Roy Cohen268c9f796273
diff --git a/frontend/src/scenes/billing/BillingProductPricingTable.tsx b/frontend/src/scenes/billing/BillingProductPricingTable.tsx
index 5837884e6c3f..8267021f0135 100644
--- a/frontend/src/scenes/billing/BillingProductPricingTable.tsx
+++ b/frontend/src/scenes/billing/BillingProductPricingTable.tsx
@@ -12,7 +12,7 @@ import {
import {
createProductValueFormatter,
- formatWithDecimals,
+ formatTierPrice,
hasDisplayFormatting,
isProductVariantPrimary,
} from './billing-utils'
@@ -39,16 +39,6 @@ export const BillingProductPricingTable = ({
billingProductLogic({ product })
)
- // Adjust tier unit price for display formatting (e.g., per-MB price → per-GB price)
- const formatTierPrice = (
- unitAmountUsd: string | null | undefined,
- prod: BillingProductV2Type | BillingProductV2AddonType
- ): string => {
- const price = parseFloat(unitAmountUsd || '0')
- const adjusted = hasDisplayFormatting(prod) && prod.display_divisor ? price * prod.display_divisor : price
- return `$${formatWithDecimals(adjusted)}`
- }
-
const showProjectedTotalWithLimitTooltip =
'addons' in product && product.projected_amount_usd_with_limit !== product.projected_amount_usd
diff --git a/frontend/src/scenes/billing/billing-utils.spec.ts b/frontend/src/scenes/billing/billing-utils.spec.ts
index 8e1da22b45aa..da27f1db57a0 100644
--- a/frontend/src/scenes/billing/billing-utils.spec.ts
+++ b/frontend/src/scenes/billing/billing-utils.spec.ts
@@ -6,6 +6,7 @@ import type { FeatureFlagsSet } from 'lib/logic/featureFlagLogic'
import { billingJson } from '~/mocks/fixtures/_billing'
import billingJsonWithFlatFee from '~/mocks/fixtures/_billing_with_flat_fee.json'
+import type { BillingProductV2Type } from '~/types'
import {
buildUsageLimitApproachingMessage,
@@ -17,6 +18,7 @@ import {
convertUsageToAmount,
formatDisplayUsage,
formatProductNames,
+ formatTierPrice,
formatWithDecimals,
getMinimumBillingAccessLevel,
getMinimumUsageSpendReadAccessLevel,
@@ -360,6 +362,23 @@ describe('formatWithDecimals', () => {
})
})
+describe('formatTierPrice', () => {
+ const withDisplay = (display_divisor: number | null, display_unit: string | null): BillingProductV2Type => ({
+ ...billingJson.products[0],
+ display_divisor,
+ display_unit,
+ })
+
+ it.each([
+ ['a per-MB-day price scaled to GB-month', '0.00000166666667', withDisplay(30000, 'GB-month'), '$0.05'],
+ ['a scaled price that rounds up to $0.1', '0.00000333333333', withDisplay(30000, 'GB-month'), '$0.1'],
+ ['a per-MB price scaled to GB', '0.00005', withDisplay(1000, 'GB'), '$0.05'],
+ ['an unscaled price at full precision', '0.000000625', withDisplay(null, null), '$0.000000625'],
+ ])('formats %s', (_name, unitAmountUsd, product, expected) => {
+ expect(formatTierPrice(unitAmountUsd, product)).toEqual(expected)
+ })
+})
+
describe('formatDisplayUsage', () => {
it('should return empty string for null value', () => {
const product = { display_divisor: 1000, display_decimals: 2, display_unit: 'GB' } as any
diff --git a/frontend/src/scenes/billing/billing-utils.ts b/frontend/src/scenes/billing/billing-utils.ts
index 9fd0178c8a82..2b2551db9559 100644
--- a/frontend/src/scenes/billing/billing-utils.ts
+++ b/frontend/src/scenes/billing/billing-utils.ts
@@ -645,6 +645,21 @@ export const formatWithDecimals = (value: number, decimals?: number): string =>
: String(value)
}
+/**
+ * Formats a tier's unit price, scaled to the product's display unit when it has one (e.g. per-MB → per-GB).
+ */
+export const formatTierPrice = (
+ unitAmountUsd: string | null | undefined,
+ product: BillingProductV2Type | BillingProductV2AddonType
+): string => {
+ const price = parseFloat(unitAmountUsd || '0')
+ if (hasDisplayFormatting(product) && product.display_divisor) {
+ // Per-unit prices are stored rounded, so scaling leaves residue: 0.00000166666667 * 30000 = 0.0500000001.
+ return `$${formatWithDecimals(price * product.display_divisor, 8)}`
+ }
+ return `$${formatWithDecimals(price)}`
+}
+
/**
* Build a human-readable list of product names (e.g., "A, B and C")
*/
diff --git a/frontend/src/scenes/billing/billingProductLogic.test.ts b/frontend/src/scenes/billing/billingProductLogic.test.ts
index 28d7c7d7669b..ce7c70bfca8e 100644
--- a/frontend/src/scenes/billing/billingProductLogic.test.ts
+++ b/frontend/src/scenes/billing/billingProductLogic.test.ts
@@ -93,6 +93,33 @@ describe('billingProductLogic', () => {
})
})
+ describe('product variants', () => {
+ // No Logs fixture exists, so reuse replay's shape: a variant product with a usage-based add-on.
+ const replay = productByType('session_replay')
+ const addonFixture = replay.addons[0]
+ const noCurrentPlan = addonFixture.plans.map((plan) => ({ ...plan, current_plan: false }))
+
+ it.each([
+ ['lists a subscribed add-on', { subscribed: true, plans: noCurrentPlan }, true],
+ ['lists an add-on on a current plan', { subscribed: false, plans: addonFixture.plans }, true],
+ ['skips an add-on the customer does not hold', { subscribed: false, plans: noCurrentPlan }, false],
+ ])('%s', (_name, addonState, listed) => {
+ const logs: BillingProductV2Type = {
+ ...replay,
+ type: 'logs',
+ addons: [{ ...addonFixture, type: 'logs_retention_custom', ...addonState }],
+ }
+ const logic = billingProductLogic({ product: logs })
+ logic.mount()
+ mounted.push(logic)
+
+ expect(logic.values.productVariants?.map(({ key, displayName }) => ({ key, displayName }))).toEqual([
+ { key: 'logs', displayName: 'Logs ingestion (14-day retention)' },
+ ...(listed ? [{ key: 'logs_retention_custom', displayName: 'Custom retention' }] : []),
+ ])
+ })
+ })
+
describe('unsubscribe survey state', () => {
it('keeps survey responses isolated per product type', async () => {
await seedBilling({})
diff --git a/frontend/src/scenes/billing/billingProductLogic.ts b/frontend/src/scenes/billing/billingProductLogic.ts
index d4bd56b44476..b9b073acc6e6 100644
--- a/frontend/src/scenes/billing/billingProductLogic.ts
+++ b/frontend/src/scenes/billing/billingProductLogic.ts
@@ -1006,6 +1006,7 @@ export const billingProductLogic = kea<billingProductLogicType>([
data_warehouse_historical: 'Free historical synced rows',
logs: 'Logs ingestion (14-day retention)',
logs_retention_30d: '30-day retention',
+ logs_retention_custom: 'Custom retention',
}
const mainProduct = product as BillingProductV2Type
@@ -1021,7 +1022,12 @@ export const billingProductLogic = kea<billingProductLogicType>([
},
]
- mainProduct.addons?.forEach((addon) => {
+ // Billing lists every offered add-on. A free-plan add-on has no price, so `subscribed` alone misses it.
+ const heldAddons = mainProduct.addons?.filter(
+ (addon) => addon.subscribed || addon.plans?.some((plan) => plan.current_plan)
+ )
+
+ heldAddons?.forEach((addon) => {
variants.push({
key: addon.type,
product: addon as BillingProductV2Type | BillingProductV2AddonType,