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(logs): gate log-based metrics on the metrics flag (#90172)

Daniel Visca3763feeeddb3
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index 39057c9de836..2aa1ec455a69 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -372,7 +372,6 @@ export const FEATURE_FLAGS = {
LOGS: 'logs', // owner: #team-logs
LOGS_ANOMALIES: 'logs-anomalies', // owner: @jonmcwest #team-logs
LOGS_IN_ERROR_TRACKING: 'logs-in-error-tracking', // owner: @jonmcwest #team-logs
- LOGS_METRIC_RULES: 'logs-metric-rules', // owner: #team-logs
LOGS_SERVICES_VIEW: 'logs-services-view', // owner: #team-logs
LOGS_SERVICES_VIEW_V2: 'logs-services-view-v2', // owner: #team-logs
LOGS_SETTINGS_JSON: 'logs-settings-json', // owner: #team-logs
diff --git a/frontend/src/scenes/settings/SettingsMap.tsx b/frontend/src/scenes/settings/SettingsMap.tsx
index 3d0077ef248c..60554d93f3c2 100644
--- a/frontend/src/scenes/settings/SettingsMap.tsx
+++ b/frontend/src/scenes/settings/SettingsMap.tsx
@@ -898,7 +898,7 @@ export const SETTINGS_MAP: SettingSection[] = [
description:
'Generate metrics from your logs at ingestion time. Metrics are computed before drop rules, so you can drop noisy logs and keep the trend.',
component: <LogsMetricRulesSection />,
- flag: LogsFeatureFlagKeys.metricRules,
+ flag: 'METRICS',
keywords: ['metric', 'metrics', 'log-based', 'generate', 'count', 'aggregate', 'logs to metrics'],
},
{
diff --git a/products/logs/backend/presentation/views/metric_rules_api.py b/products/logs/backend/presentation/views/metric_rules_api.py
index c9ec22549290..493294ec3c32 100644
--- a/products/logs/backend/presentation/views/metric_rules_api.py
+++ b/products/logs/backend/presentation/views/metric_rules_api.py
@@ -230,7 +230,10 @@ class LogsMetricRuleViewSet(TeamAndOrgViewSetMixin, viewsets.ModelViewSet):
queryset = LogsMetricRule.objects.unscoped().order_by("created_at")
serializer_class = LogsMetricRuleSerializer
lookup_field = "id"
- posthog_feature_flag = "logs-metric-rules"
+ # A rule's output is only readable in the Metrics product, so the Metrics alpha flag is what
+ # admits a team. Whether a rule then runs is a separate, ops-level decision: ingestion checks
+ # its own LOGS_METRICS_RULES_ENABLED_TEAMS allowlist, which no feature flag feeds.
+ posthog_feature_flag = "metrics"
permission_classes = [PostHogFeatureFlagPermission, MetricRuleCanonicalTeamPermission]
@cached_property
diff --git a/products/logs/backend/test/test_metric_rules_api.py b/products/logs/backend/test/test_metric_rules_api.py
index 3af7011a1248..f7204d10c9c2 100644
--- a/products/logs/backend/test/test_metric_rules_api.py
+++ b/products/logs/backend/test/test_metric_rules_api.py
@@ -257,13 +257,21 @@ class TestLogsMetricRulesAPI(APIBaseTest):
assert body["enabled"] is True
assert body["version"] == created["version"] + 1
- def test_requires_feature_flag(self):
- self._ff_patcher.stop()
- with patch("posthoganalytics.feature_enabled", return_value=False):
+ @parameterized.expand(
+ [
+ ("no flags", (), status.HTTP_403_FORBIDDEN),
+ ("the retired logs flag alone", ("logs-metric-rules",), status.HTTP_403_FORBIDDEN),
+ ("the metrics flag", ("metrics",), status.HTTP_201_CREATED),
+ ]
+ )
+ def test_metrics_feature_flag_admits_the_team(
+ self, _label: str, enabled_flags: tuple[str, ...], expected_status: int
+ ) -> None:
+ # A rule's output is only readable in Metrics, so that alpha flag is the one that admits a
+ # team. `logs-metric-rules` is retired and must not open the API on its own.
+ with patch("posthoganalytics.feature_enabled", side_effect=lambda flag, *_, **__: flag in enabled_flags):
response = self.client.post(self.base_url, self._payload(), format="json")
- assert response.status_code == status.HTTP_403_FORBIDDEN
- self._ff_patcher = patch("posthoganalytics.feature_enabled", return_value=True)
- self._ff_patcher.start()
+ assert response.status_code == expected_status, response.json()
def test_child_environment_url_targets_canonical_team(self):
# RootTeamMixin.save() stores rules under the parent (canonical) team, so the
diff --git a/products/logs/frontend/components/LogsMetricRules/LogsMetricRulesSection.tsx b/products/logs/frontend/components/LogsMetricRules/LogsMetricRulesSection.tsx
index 41fd57db91d1..aabf23ee82a9 100644
--- a/products/logs/frontend/components/LogsMetricRules/LogsMetricRulesSection.tsx
+++ b/products/logs/frontend/components/LogsMetricRules/LogsMetricRulesSection.tsx
@@ -6,13 +6,12 @@ import { useFeatureFlag } from 'lib/hooks/useFeatureFlag'
import { More } from 'lib/lemon-ui/LemonButton/More'
import { LogsMetricRuleApi } from 'products/logs/frontend/generated/api.schemas'
-import { LogsFeatureFlagKeys } from 'products/logs/frontend/logsFeatureFlagKeys'
import { LogsMetricRuleModal } from './LogsMetricRuleModal'
import { logsMetricRulesSectionLogic } from './logsMetricRulesSectionLogic'
export function LogsMetricRulesSection(): JSX.Element | null {
- const enabled = useFeatureFlag(LogsFeatureFlagKeys.metricRules)
+ const enabled = useFeatureFlag('METRICS')
if (!enabled) {
return null
}
diff --git a/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx b/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx
index 00bc3e9a8c44..805ef8c71a4d 100644
--- a/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx
+++ b/products/logs/frontend/components/LogsViewer/LogRowFAB/LogRowFAB.tsx
@@ -28,7 +28,6 @@ import { logDetailsModalLogic } from 'products/logs/frontend/components/LogsView
import { logsViewerLogic } from 'products/logs/frontend/components/LogsViewer/logsViewerLogic'
import { useCellScrollControls } from 'products/logs/frontend/components/VirtualizedLogsList/useCellScroll'
import { logsConfigLogic } from 'products/logs/frontend/logsConfigLogic'
-import { LogsFeatureFlagKeys } from 'products/logs/frontend/logsFeatureFlagKeys'
import { ParsedLogMessage } from 'products/logs/frontend/types'
import { getSessionIdFromLogAttributes } from 'products/logs/frontend/utils'
import { traceUrl } from 'products/tracing/frontend/traceLinks'
@@ -59,7 +58,7 @@ export function LogRowFAB({
const { openWithSeed } = useActions(logsMetricRuleQuickCreateLogic)
const { startScrolling, stopScrolling } = useCellScrollControls({ id, cellKey: 'message' })
const sessionId = getSessionIdFromLogAttributes(log.attributes, log.resource_attributes, configuredSessionIdKeys)
- const metricRulesEnabled = useFeatureFlag(LogsFeatureFlagKeys.metricRules)
+ const metricRulesEnabled = useFeatureFlag('METRICS')
const metricsEditorDisabledReason = getAccessControlDisabledReason(
AccessControlResourceType.Metrics,
AccessControlLevel.Editor
diff --git a/products/logs/frontend/logsFeatureFlagKeys.ts b/products/logs/frontend/logsFeatureFlagKeys.ts
index b617b8a14c07..96fe7954b659 100644
--- a/products/logs/frontend/logsFeatureFlagKeys.ts
+++ b/products/logs/frontend/logsFeatureFlagKeys.ts
@@ -2,9 +2,7 @@ import type { FeatureFlagLookupKey } from 'lib/constants'
/** `keyof FEATURE_FLAGS` for `useFeatureFlag` and settings `flag` — not remote slug strings. */
export const LogsFeatureFlagKeys = {
- metricRules: 'LOGS_METRIC_RULES',
retentionRules: 'LOGS_SETTINGS_RETENTION_RULES',
} as const satisfies {
- metricRules: FeatureFlagLookupKey
retentionRules: FeatureFlagLookupKey
}
diff --git a/products/metrics/frontend/components/MetricsLogsSourceTag.tsx b/products/metrics/frontend/components/MetricsLogsSourceTag.tsx
index a30f8422c7e3..540c2904418a 100644
--- a/products/metrics/frontend/components/MetricsLogsSourceTag.tsx
+++ b/products/metrics/frontend/components/MetricsLogsSourceTag.tsx
@@ -17,7 +17,7 @@ export interface MetricsLogsSourceTagProps {
* the logs the rule matches, and the rule itself in settings.
*/
export function MetricsLogsSourceTag({ metricName }: MetricsLogsSourceTagProps): JSX.Element | null {
- const metricRulesEnabled = useFeatureFlag('LOGS_METRIC_RULES')
+ const metricRulesEnabled = useFeatureFlag('METRICS')
if (!metricRulesEnabled || !metricName.trim()) {
return null
}