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.

feat(metrics): register metrics in onboarding and roll up activation (#75830)

Daniel Visca8c36e42b1290
diff --git a/docs/onboarding/metrics/index.ts b/docs/onboarding/metrics/index.ts
new file mode 100644
index 000000000000..17cb560c9eba
--- /dev/null
+++ b/docs/onboarding/metrics/index.ts
@@ -0,0 +1 @@
+export { OpenTelemetryInstallation } from './opentelemetry'
diff --git a/docs/onboarding/metrics/opentelemetry.tsx b/docs/onboarding/metrics/opentelemetry.tsx
new file mode 100644
index 000000000000..3329b20466ae
--- /dev/null
+++ b/docs/onboarding/metrics/opentelemetry.tsx
@@ -0,0 +1,119 @@
+import { OnboardingComponentsContext, createInstallation } from 'scenes/onboarding/shared/OnboardingDocsContentWrapper'
+
+import { StepDefinition } from '../steps'
+
+export const getOpenTelemetrySteps = (ctx: OnboardingComponentsContext): StepDefinition[] => {
+ const { CodeBlock, Markdown, dedent } = ctx
+
+ return [
+ {
+ title: 'Scrape a Prometheus endpoint',
+ badge: 'recommended',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ If your services already expose a Prometheus \`/metrics\` endpoint, run the PostHog
+ metrics agent. It scrapes those endpoints and forwards them to PostHog, so your
+ application code does not change.
+ `}
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'bash',
+ file: 'Docker',
+ code: dedent`
+ docker run -d --name posthog-metrics-agent \\
+ -e POSTHOG_API_KEY=<ph_project_token> \\
+ -e POSTHOG_HOST=<ph_client_api_host> \\
+ -e SCRAPE_TARGETS=your-app:9090,your-worker:9091 \\
+ posthog/metrics-agent:latest
+ `,
+ },
+ ]}
+ />
+ <Markdown>
+ {dedent`
+ \`SCRAPE_TARGETS\` is a comma-separated list of \`host:port\` targets to scrape.
+
+ On Kubernetes, the Helm chart in \`products/metrics/agent/chart\` runs the same image.
+ Set \`shards\` to spread targets across a fleet, and \`persistence.enabled=true\` to keep
+ the export queue across restarts.
+
+ Counters and histograms scraped with OpenMetrics exemplars become clickable trace
+ links. Your Prometheus client has to attach the exemplars, the agent only preserves them.
+ `}
+ </Markdown>
+ </>
+ ),
+ },
+ {
+ title: 'Send metrics over OTLP',
+ badge: 'optional',
+ content: (
+ <>
+ <Markdown>
+ {dedent`
+ If you instrument your application directly, PostHog accepts metrics from any
+ OpenTelemetry client over OTLP HTTP. There is no PostHog-specific package to install,
+ use the standard OpenTelemetry libraries for your language.
+ `}
+ </Markdown>
+ <CodeBlock
+ blocks={[
+ {
+ language: 'bash',
+ file: 'Environment variables',
+ code: dedent`
+ OTEL_EXPORTER_OTLP_METRICS_ENDPOINT="<ph_client_api_host>/i/v1/metrics"
+ OTEL_EXPORTER_OTLP_METRICS_HEADERS="Authorization=Bearer <ph_project_token>"
+ OTEL_SERVICE_NAME="my-app"
+ `,
+ },
+ {
+ language: 'yaml',
+ file: 'OTel Collector',
+ code: dedent`
+ receivers:
+ otlp:
+ protocols:
+ http:
+ endpoint: 0.0.0.0:4318
+
+ processors:
+ batch:
+
+ exporters:
+ otlphttp/posthog:
+ metrics_endpoint: "<ph_client_api_host>/i/v1/metrics"
+ headers:
+ Authorization: "Bearer <ph_project_token>"
+
+ service:
+ pipelines:
+ metrics:
+ receivers: [otlp]
+ processors: [batch]
+ exporters: [otlphttp/posthog]
+ `,
+ },
+ ]}
+ />
+ <Markdown>
+ {dedent`
+ The endpoint accepts OTLP over HTTP as \`application/x-protobuf\` or
+ \`application/json\`. gRPC is not supported, use the HTTP transport instead.
+
+ Gauges, sums, histograms, exponential histograms, and summaries are all accepted.
+ Keep label cardinality low: values like user IDs or request IDs create a new series
+ each time and get rate limited.
+ `}
+ </Markdown>
+ </>
+ ),
+ },
+ ]
+}
+
+export const OpenTelemetryInstallation = createInstallation(getOpenTelemetrySteps)
diff --git a/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts b/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts
index e33b5626ca6c..7292242b9fa0 100644
--- a/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts
+++ b/frontend/src/scenes/onboarding/legacy/onboardingLogic.test.ts
@@ -194,6 +194,18 @@ describe('onboardingLogic — flow composition', () => {
INSTALL_DEDUP_KEYS.OPENTELEMETRY,
])
})
+
+ // Metrics and Logs both send over OTel, but their install steps are NOT
+ // functionally identical (Metrics is OTLP/scrape-agent only; Logs offers 10
+ // SDK-specific flows). Collapsing them would drop the loser's instruction map,
+ // so picking both must keep both install steps regardless of which is primary.
+ it('Metrics primary + Logs secondary keeps both install steps (no dedup)', () => {
+ logic.actions.setProductKey(ProductKey.METRICS)
+ logic.actions.setSecondaryProductKeys([ProductKey.LOGS])
+
+ const installs = logic.values.flow.filter((s) => s.stepKey === OnboardingStepKey.INSTALL)
+ expect(installs.map((s) => s.id)).toEqual(['install:metrics', 'install:logs'])
+ })
})
describe('install-step — no dedup', () => {
diff --git a/frontend/src/scenes/onboarding/legacy/sdks/metrics/MetricsSDKInstructions.tsx b/frontend/src/scenes/onboarding/legacy/sdks/metrics/MetricsSDKInstructions.tsx
new file mode 100644
index 000000000000..db11daeaf60f
--- /dev/null
+++ b/frontend/src/scenes/onboarding/legacy/sdks/metrics/MetricsSDKInstructions.tsx
@@ -0,0 +1,16 @@
+import { OpenTelemetryInstallation } from '@posthog/shared-onboarding/metrics'
+
+import { SDKInstructionsMap, SDKKey } from '~/types'
+
+import { withOnboardingDocsWrapper } from '../shared/onboardingWrappers'
+
+// Metrics arrives over OTLP, either from the scrape agent or straight from an OTel
+// exporter. Both paths are steps of the one entry, so wizardIntegrationName is
+// omitted: the posthog-wizard doesn't set up OTLP metrics.
+const MetricsOpenTelemetryInstructionsWrapper = withOnboardingDocsWrapper({
+ Installation: OpenTelemetryInstallation,
+})
+
+export const MetricsSDKInstructions: SDKInstructionsMap = {
+ [SDKKey.OPENTELEMETRY]: MetricsOpenTelemetryInstructionsWrapper,
+}
diff --git a/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.test.ts b/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.test.ts
new file mode 100644
index 000000000000..49aa36e573c4
--- /dev/null
+++ b/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.test.ts
@@ -0,0 +1,51 @@
+import { ProductKey } from '~/queries/schema/schema-general'
+import { OnboardingStepKey } from '~/types'
+
+import { availableOnboardingProducts } from '../shared/utils'
+import { onboardingProviderRegistry } from './stepProviderRegistry'
+import { INSTALL_DEDUP_KEYS, type OnboardingFlowContext } from './types'
+
+function context(primary: ProductKey): OnboardingFlowContext {
+ return {
+ primary,
+ secondaries: [],
+ role: 'primary',
+ currentTeam: null,
+ billing: null,
+ isCloudOrDev: true,
+ subscribedDuringOnboarding: false,
+ canInviteTeammates: true,
+ }
+}
+
+describe('onboardingProviderRegistry', () => {
+ // Onboarding a product means registering it twice: here for its steps, and in
+ // availableOnboardingProducts for the picker. Either half alone ships a product
+ // that can't be picked, or one that picks into a flow with no steps.
+ it('covers exactly the products the picker offers', () => {
+ expect(Object.keys(onboardingProviderRegistry).sort()).toEqual(Object.keys(availableOnboardingProducts).sort())
+ })
+
+ it('sends metrics through an install step and lands on the metrics scene', () => {
+ const provider = onboardingProviderRegistry[ProductKey.METRICS]
+
+ const steps = provider!.steps(context(ProductKey.METRICS))
+
+ expect(steps).toHaveLength(1)
+ expect(steps[0].productKey).toBe(ProductKey.METRICS)
+ expect(steps[0].stepKey).toBe(OnboardingStepKey.INSTALL)
+ expect(provider!.completeRedirectUrl?.()).toBe('/metrics')
+ })
+
+ // Metrics and Logs both arrive over OTel, but their install experiences differ:
+ // Metrics is OTLP/scrape-agent only, while Logs offers Node.js, Python, Go, Java,
+ // and mobile SDK flows. Sharing a dedupKey would collapse the two and drop the
+ // loser's instruction map, so Metrics must NOT carry the OpenTelemetry dedupKey.
+ it('does not share the OpenTelemetry dedup key with logs', () => {
+ const metricsStep = onboardingProviderRegistry[ProductKey.METRICS]!.steps(context(ProductKey.METRICS))[0]
+ const logsStep = onboardingProviderRegistry[ProductKey.LOGS]!.steps(context(ProductKey.LOGS))[0]
+
+ expect(logsStep.dedupKey).toBe(INSTALL_DEDUP_KEYS.OPENTELEMETRY)
+ expect(metricsStep.dedupKey).toBeUndefined()
+ })
+})
diff --git a/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.ts b/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.ts
index 34716d2832a5..cd3b2182e061 100644
--- a/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.ts
+++ b/frontend/src/scenes/onboarding/legacy/stepProviderRegistry.ts
@@ -8,6 +8,7 @@ import { experimentsOnboarding } from 'products/experiments/frontend/onboarding/
import { featureFlagsOnboarding } from 'products/feature_flags/frontend/onboarding/steps'
import { logsOnboarding } from 'products/logs/frontend/onboarding/steps'
import { mcpAnalyticsOnboarding } from 'products/mcp_analytics/frontend/onboarding/steps'
+import { metricsOnboarding } from 'products/metrics/frontend/onboarding/steps'
import { productAnalyticsOnboarding } from 'products/product_analytics/frontend/onboarding/steps'
import { sessionReplayOnboarding } from 'products/session_replay/frontend/onboarding/steps'
import { surveysOnboarding } from 'products/surveys/frontend/onboarding/steps'
@@ -38,6 +39,7 @@ export const onboardingProviderRegistry: Partial<Record<ProductKey, ProductOnboa
[ProductKey.AI_OBSERVABILITY]: aiObservabilityOnboarding,
[ProductKey.WORKFLOWS]: workflowsOnboarding,
[ProductKey.LOGS]: logsOnboarding,
+ [ProductKey.METRICS]: metricsOnboarding,
[ProductKey.MCP_ANALYTICS]: mcpAnalyticsOnboarding,
[ProductKey.CONVERSATIONS]: conversationsOnboarding,
}
diff --git a/frontend/src/scenes/onboarding/shared/utils.tsx b/frontend/src/scenes/onboarding/shared/utils.tsx
index a2503d125528..d0627e9d79df 100644
--- a/frontend/src/scenes/onboarding/shared/utils.tsx
+++ b/frontend/src/scenes/onboarding/shared/utils.tsx
@@ -319,6 +319,23 @@ export const availableOnboardingProducts: AvailableOnboardingProducts = {
scene: Scene.Logs,
setupEffort: 'low',
},
+ [ProductKey.METRICS]: {
+ name: 'Metrics',
+ description: 'Chart and alert on the metrics your services already expose',
+ userCentricDescription: 'See how your services are performing over time',
+ capabilities: ['Prometheus and OpenTelemetry ingest', 'Metric charts and dashboards', 'Anomaly detection'],
+ valueProps: [
+ { title: 'Bring your existing metrics', problem: 'Scrape a Prometheus endpoint without changing your app' },
+ { title: 'Charts and dashboards', problem: 'Watch latency, throughput, and error rates over time' },
+ { title: 'Metric to trace links', problem: 'Jump from a spike straight to the trace behind it' },
+ ],
+ hedgehog: HedgehogChart,
+ icon: 'IconGraph',
+ iconColor: 'var(--color-product-metrics-light)',
+ url: urls.metrics(),
+ scene: Scene.Metrics,
+ setupEffort: 'low',
+ },
[ProductKey.MCP_ANALYTICS]: {
name: 'MCP analytics',
description: 'See how AI agents use your MCP server — tool calls, intent, and failures',
diff --git a/frontend/src/types.ts b/frontend/src/types.ts
index 63e4328c68d6..9cb42a8166e7 100644
--- a/frontend/src/types.ts
+++ b/frontend/src/types.ts
@@ -7073,6 +7073,7 @@ export type AvailableOnboardingProducts = Record<
| ProductKey.AI_OBSERVABILITY
| ProductKey.WORKFLOWS
| ProductKey.LOGS
+ | ProductKey.METRICS
| ProductKey.MCP_ANALYTICS
| ProductKey.CONVERSATIONS,
OnboardingProduct
diff --git a/posthog/models/product_intent/product_intent.py b/posthog/models/product_intent/product_intent.py
index 18d91eaff98c..76f57261e979 100644
--- a/posthog/models/product_intent/product_intent.py
+++ b/posthog/models/product_intent/product_intent.py
@@ -228,6 +228,27 @@ class ProductIntent(UUIDTModel, RootTeamMixin):
contexts = intent.contexts or {}
return contexts.get("mcp_analytics_viewed", 0) >= 1
+ def has_activated_metrics(self) -> bool:
+ # The user has charted or queried metrics. Charting/querying is only possible
+ # once metrics have reached the team (a metric name has to exist to pick), so an
+ # engagement signal is itself proof of ingestion — and ingestion on its own is a
+ # connected pipeline, not an activated product.
+ #
+ # We deliberately do NOT gate on `metrics_first_ingested`: that context fires only
+ # when the frontend observes a no-metrics -> has-metrics flip in-session, so a team
+ # that already had metrics before its first check never records it and could never
+ # activate on later query intents.
+ intent = ProductIntent.objects.filter(
+ team=self.team,
+ product_type="metrics",
+ ).first()
+
+ if not intent:
+ return False
+
+ contexts = intent.contexts or {}
+ return contexts.get("metrics_viewer_query_run", 0) >= 1 or contexts.get("metrics_sql_query_run", 0) >= 1
+
def has_activated_workflows(self) -> bool:
# At least one workflow needs to be active (not just drafted)
return HogFlow.objects.filter(team=self.team, status=HogFlow.State.ACTIVE).exists()
@@ -340,6 +361,7 @@ ACTIVATION_CHECKS: dict[str, Callable[[ProductIntent], bool]] = {
"surveys": ProductIntent.has_activated_surveys,
"llm_analytics": ProductIntent.has_activated_llm_analytics,
"mcp_analytics": ProductIntent.has_activated_mcp_analytics,
+ "metrics": ProductIntent.has_activated_metrics,
"workflows": ProductIntent.has_activated_workflows,
}
diff --git a/posthog/models/test/test_product_intent.py b/posthog/models/test/test_product_intent.py
index 79d3d9d7f1e3..2eb61ce40864 100644
--- a/posthog/models/test/test_product_intent.py
+++ b/posthog/models/test/test_product_intent.py
@@ -842,6 +842,46 @@ class TestProductIntent(BaseTest):
assert self.product_intent.has_activated_mcp_analytics() is False
+ def _make_metrics_intent(self, contexts: dict) -> ProductIntent:
+ ProductIntent.objects.filter(team=self.team, product_type=ProductKey.METRICS).delete()
+ return ProductIntent.objects.create(
+ team=self.team,
+ product_type=ProductKey.METRICS,
+ contexts=contexts,
+ )
+
+ @parameterized.expand(
+ [
+ # Charting or querying is only possible once metrics have reached the team,
+ # so any engagement signal is itself proof of ingestion + activation.
+ ("charted", {"metrics_viewer_query_run": 1}, True),
+ ("queried in sql", {"metrics_sql_query_run": 2}, True),
+ (
+ "first-ingested recorded then charted",
+ {"metrics_first_ingested": 1, "metrics_viewer_query_run": 1},
+ True,
+ ),
+ # Pre-existing-metrics teams never record the transition-only first-ingested
+ # context, so engagement alone must still activate them.
+ ("charted without first-ingested intent", {"metrics_viewer_query_run": 3}, True),
+ # Ingestion alone (no engagement) is a connected pipeline, not activation.
+ ("first-ingested but never looked at", {"metrics_first_ingested": 1}, False),
+ ("no engagement at all", {}, False),
+ ]
+ )
+ def test_has_activated_metrics(self, _name: str, contexts: dict, expected: bool) -> None:
+ intent = self._make_metrics_intent(contexts)
+
+ assert intent.has_activated_metrics() is expected
+
+ def test_check_and_update_activation_activates_metrics(self) -> None:
+ # Guards the registration, not the criterion: an unregistered check never runs.
+ intent = self._make_metrics_intent({"metrics_first_ingested": 1, "metrics_viewer_query_run": 1})
+
+ assert intent.check_and_update_activation(skip_reporting=True) is True
+ intent.refresh_from_db()
+ assert intent.activated_at is not None
+
def test_has_activated_workflows_with_active_workflow(self):
self.product_intent.product_type = ProductKey.WORKFLOWS
self.product_intent.save()
diff --git a/products/metrics/frontend/onboarding/steps.tsx b/products/metrics/frontend/onboarding/steps.tsx
new file mode 100644
index 000000000000..5423e29852a8
--- /dev/null
+++ b/products/metrics/frontend/onboarding/steps.tsx
@@ -0,0 +1,25 @@
+import { MetricsSDKInstructions } from 'scenes/onboarding/legacy/sdks/metrics/MetricsSDKInstructions'
+import { OnboardingInstallStep } from 'scenes/onboarding/legacy/sdks/OnboardingInstallStep'
+import { type ProductOnboardingProvider } from 'scenes/onboarding/legacy/types'
+import { urls } from 'scenes/urls'
+
+import { ProductKey } from '~/queries/schema/schema-general'
+import { OnboardingStepKey } from '~/types'
+
+export const metricsOnboarding: ProductOnboardingProvider = {
+ steps: (ctx) => [
+ {
+ id: `${OnboardingStepKey.INSTALL}:${ProductKey.METRICS}`,
+ productKey: ProductKey.METRICS,
+ stepKey: OnboardingStepKey.INSTALL,
+ role: ctx.role,
+ // No dedupKey with Logs: both send over OTel, but the install steps are not
+ // functionally identical. Metrics is OTLP/scrape-agent only; Logs offers 10
+ // SDK-specific flows (Node.js, Python, Go, Java, mobile) plus its own OTel
+ // config. Sharing a key would collapse the two and drop the loser's
+ // instruction map depending on which product is primary.
+ render: () => <OnboardingInstallStep sdkInstructionMap={MetricsSDKInstructions} hideInstallationCheck />,
+ },
+ ],
+ completeRedirectUrl: () => urls.metrics(),
+}