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(logs): add flag-gated v2 services view shell (#83253)

Jon McCallume3320a043e9b
diff --git a/frontend/src/lib/constants.tsx b/frontend/src/lib/constants.tsx
index be4651c6987a..4cbd644c8ae3 100644
--- a/frontend/src/lib/constants.tsx
+++ b/frontend/src/lib/constants.tsx
@@ -368,6 +368,7 @@ export const FEATURE_FLAGS = {
LOGS_PATTERNS_VIEW: 'logs-patterns-view', // owner: #team-logs
LOGS_SAVED_VIEWS: 'logs-saved-views', // 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: 'logs-settings', // owner: #team-logs
LOGS_SETTINGS_DROP_RULES: 'logs-settings-drop-rules', // owner: #team-logs
LOGS_SETTINGS_JSON: 'logs-settings-json', // owner: #team-logs
diff --git a/products/logs/frontend/LogsScene.stories.tsx b/products/logs/frontend/LogsScene.stories.tsx
index d57772d80fc0..bd4c1ef91daf 100644
--- a/products/logs/frontend/LogsScene.stories.tsx
+++ b/products/logs/frontend/LogsScene.stories.tsx
@@ -421,16 +421,18 @@ export default {
title: 'Scenes-App/Logs',
decorators: [
// mocks used by all stories in this file
+ // Endpoint prefix follows the caller: the generated client is project-scoped,
+ // while the handwritten ApiRequest helpers are environment-scoped.
mswDecorator({
get: {
- '/api/environments/:team_id/logs/attributes': attributesMock,
+ '/api/projects/:team_id/logs/attributes': attributesMock,
'/api/environments/:team_id/logs/values': valuesMock,
'/api/environments/:team_id/logs/has_logs': () => [200, { hasLogs: true }],
},
post: {
'/api/environments/:team_id/logs/query': queryMock,
'/api/environments/:team_id/logs/sparkline': sparklineMock,
- '/api/environments/:team_id/logs/services': servicesMock,
+ '/api/projects/:team_id/logs/services': servicesMock,
},
}),
],
@@ -462,9 +464,28 @@ export function LogsSceneServicesTab(): JSX.Element {
}, [])
return <App />
}
+// Story parameters replace the meta's rather than merging, so each list is complete.
LogsSceneServicesTab.parameters = {
- featureFlags: [FEATURE_FLAGS.LOGS_SERVICES_VIEW],
+ featureFlags: [FEATURE_FLAGS.LOGS_TABBED_VIEW, FEATURE_FLAGS.LOGS_SERVICES_VIEW],
testOptions: {
waitForSelector: '.LemonTable',
},
}
+
+export function LogsSceneServicesTabV2(): JSX.Element {
+ useEffect(() => {
+ router.actions.push(combineUrl(urls.logs(), { activeTab: 'services' }).url)
+ }, [])
+ return <App />
+}
+LogsSceneServicesTabV2.parameters = {
+ featureFlags: [
+ FEATURE_FLAGS.LOGS_TABBED_VIEW,
+ FEATURE_FLAGS.LOGS_SERVICES_VIEW,
+ FEATURE_FLAGS.LOGS_SERVICES_VIEW_V2,
+ ],
+ testOptions: {
+ // v2-specific, so this fails rather than passes if the gate falls through to the v1 table.
+ waitForSelector: '[data-attr="logs-services-view-mode-list"]',
+ },
+}
diff --git a/products/logs/frontend/LogsScene.tsx b/products/logs/frontend/LogsScene.tsx
index 8af84d552a03..8088a1d9e721 100644
--- a/products/logs/frontend/LogsScene.tsx
+++ b/products/logs/frontend/LogsScene.tsx
@@ -17,6 +17,7 @@ import { ProductKey } from '~/queries/schema/schema-general'
import { LogsAlertingSection } from 'products/logs/frontend/components/LogsAlerting/LogsAlertingSection'
import { LogsServices } from 'products/logs/frontend/components/LogsServices/LogsServices'
+import { LogsServicesV2 } from 'products/logs/frontend/components/LogsServices/LogsServicesV2'
import { LogsSqlEditor } from 'products/logs/frontend/components/LogsSqlEditor/LogsSqlEditor'
import { LogsTransformations } from 'products/logs/frontend/components/LogsTransformations/LogsTransformations'
import { LogsViewer } from 'products/logs/frontend/components/LogsViewer'
@@ -94,6 +95,8 @@ const LogsSceneTabbedContent = (): JSX.Element => {
const { setActiveTab } = useActions(logsSceneLogic)
const { hasLogs, teamHasLogsCheckFailed } = useValues(logsIngestionLogic)
const showServicesView = useFeatureFlag('LOGS_SERVICES_VIEW')
+ const showServicesV2 = useFeatureFlag('LOGS_SERVICES_VIEW_V2')
+ const showServices = activeTab === 'services' && showServicesView
const showAlerting = useFeatureFlag('LOGS_ALERTING')
const showTransformations = useFeatureFlag('LOGS_TRANSFORMATIONS')
const showAnomalies = useFeatureFlag('LOGS_ANOMALIES')
@@ -151,7 +154,8 @@ const LogsSceneTabbedContent = (): JSX.Element => {
</div>
</LogsSetupPrompt>
</div>
- {activeTab === 'services' && showServicesView && (
+ {showServices && showServicesV2 && <LogsServicesV2 />}
+ {showServices && !showServicesV2 && (
<>
<LogsServices />
<LogsViewerModal />
diff --git a/products/logs/frontend/components/LogsServices/LogsServicesV2.tsx b/products/logs/frontend/components/LogsServices/LogsServicesV2.tsx
new file mode 100644
index 000000000000..96fc35b5c89d
--- /dev/null
+++ b/products/logs/frontend/components/LogsServices/LogsServicesV2.tsx
@@ -0,0 +1,114 @@
+import { useActions, useValues } from 'kea'
+
+import { LemonBanner, LemonInput, LemonSegmentedButton, LemonSelect, LemonTable, LemonTag } from '@posthog/lemon-ui'
+import type { LemonSegmentedButtonOption, LemonTableColumns } from '@posthog/lemon-ui'
+
+import { humanFriendlyNumber } from 'lib/utils/numbers'
+
+import { logsServicesLogic, SERVICES_PAGE_SIZE, ServiceRow, ServicesViewMode } from './logsServicesLogic'
+
+const DATE_OPTIONS = [
+ { value: '-1h', label: 'Last hour' },
+ { value: '-24h', label: 'Last 24 hours' },
+ { value: '-7d', label: 'Last 7 days' },
+ { value: '-30d', label: 'Last 30 days' },
+]
+
+const VIEW_MODE_OPTIONS: LemonSegmentedButtonOption<ServicesViewMode>[] = [
+ { value: 'list', label: 'List', 'data-attr': 'logs-services-view-mode-list' },
+ { value: 'grid', label: 'Grid', 'data-attr': 'logs-services-view-mode-grid' },
+]
+
+const COLUMNS: LemonTableColumns<ServiceRow> = [
+ { title: 'Service name', dataIndex: 'service_name' },
+ {
+ title: 'Log volume',
+ dataIndex: 'log_count',
+ align: 'right',
+ render: (_, row) => humanFriendlyNumber(row.log_count),
+ },
+ {
+ title: 'Error rate',
+ dataIndex: 'error_rate',
+ align: 'right',
+ render: (_, row) => {
+ const type = row.error_rate > 0.1 ? 'danger' : row.error_rate > 0.01 ? 'warning' : 'success'
+ return <LemonTag type={type}>{(row.error_rate * 100).toFixed(1)}%</LemonTag>
+ },
+ },
+]
+
+function ServicesGrid(): JSX.Element {
+ return (
+ <div className="p-4 text-center text-muted">
+ Grid view is not built yet. Switch to List to see your services.
+ </div>
+ )
+}
+
+export function LogsServicesV2(): JSX.Element {
+ const { pageRows, services, totalServices, servicesDataLoading, searchTerm, dateFrom, page, viewMode } =
+ useValues(logsServicesLogic)
+ const { setDateFrom, setSearchTerm, setPage, setViewMode } = useActions(logsServicesLogic)
+
+ return (
+ <div className="flex flex-col gap-2 py-2 flex-1 min-h-0">
+ {totalServices > services.length && (
+ <LemonBanner type="info" className="mb-0">
+ Showing the top {humanFriendlyNumber(services.length)} of {humanFriendlyNumber(totalServices)}{' '}
+ {searchTerm ? 'matching services' : 'services'} by volume.{' '}
+ {searchTerm ? 'Refine your search to see the rest.' : 'Use search to find the rest.'}
+ </LemonBanner>
+ )}
+ <div className="flex items-center justify-between gap-2">
+ <LemonSegmentedButton
+ size="small"
+ value={viewMode}
+ onChange={setViewMode}
+ options={VIEW_MODE_OPTIONS}
+ />
+ <div className="flex items-center gap-2">
+ <LemonInput
+ size="small"
+ type="search"
+ placeholder="Search services"
+ value={searchTerm}
+ onChange={setSearchTerm}
+ />
+ <LemonSelect
+ size="small"
+ value={dateFrom}
+ onChange={(value) => value && setDateFrom(value)}
+ options={DATE_OPTIONS}
+ />
+ </div>
+ </div>
+ {/* The scene container is a fixed height and does not scroll, so this region has to. */}
+ <div className="flex-1 min-h-0 overflow-y-auto" data-attr="logs-services-v2">
+ {viewMode === 'grid' ? (
+ <ServicesGrid />
+ ) : (
+ <LemonTable
+ columns={COLUMNS}
+ dataSource={pageRows}
+ loading={servicesDataLoading}
+ pagination={{
+ controlled: true,
+ pageSize: SERVICES_PAGE_SIZE,
+ currentPage: page,
+ entryCount: services.length,
+ onForward: () => setPage(page + 1),
+ onBackward: () => setPage(page - 1),
+ useUrl: false,
+ }}
+ emptyState={
+ searchTerm ? 'No services match your search' : 'No services found in this time range'
+ }
+ rowKey="service_name"
+ size="small"
+ />
+ )}
+ </div>
+ </div>
+ )
+}
diff --git a/products/logs/frontend/components/LogsServices/logsServicesLogic.ts b/products/logs/frontend/components/LogsServices/logsServicesLogic.ts
index a6c82c4a0439..308e029dd253 100644
--- a/products/logs/frontend/components/LogsServices/logsServicesLogic.ts
+++ b/products/logs/frontend/components/LogsServices/logsServicesLogic.ts
@@ -14,6 +14,9 @@ import type {
export type ServiceRow = _LogsServiceAggregateApi
+/** How the v2 services surface draws the same list. Presentation only: it never changes which services are in the set. */
+export type ServicesViewMode = 'list' | 'grid'
+
// Must stay at or below the backend's SPARKLINE_SERVICES_LIMIT: a page-turn
// sparkline request covers at most that many names, and names beyond it would
// come back without data.
@@ -57,6 +60,7 @@ export interface logsServicesLogicValues {
sparklinePoints: _LogsServicesSparklineBucketApi[]
sparklineRequested: Record<string, boolean>
totalServices: number
+ viewMode: ServicesViewMode
}
// Generated by kea-typegen. Update if you're an agent, ignore if you're human.
@@ -97,6 +101,9 @@ export interface logsServicesLogicActions {
setSorting: (sorting: Sorting | null) => {
sorting: Sorting | null
}
+ setViewMode: (viewMode: ServicesViewMode) => {
+ viewMode: ServicesViewMode
+ }
unmarkSparklineRequested: (serviceNames: string[]) => {
serviceNames: string[]
}
@@ -136,6 +143,7 @@ export const logsServicesLogic = kea<logsServicesLogicType>([
setDateFrom: (dateFrom: string) => ({ dateFrom }),
setSearchTerm: (searchTerm: string) => ({ searchTerm }),
setPage: (page: number) => ({ page }),
+ setViewMode: (viewMode: ServicesViewMode) => ({ viewMode }),
setSorting: (sorting: Sorting | null) => ({ sorting }),
ensureSparklinesForPage: true,
markSparklineRequested: (serviceNames: string[]) => ({ serviceNames }),
@@ -156,6 +164,12 @@ export const logsServicesLogic = kea<logsServicesLogicType>([
setSearchTerm: (_, { searchTerm }) => searchTerm,
},
],
+ viewMode: [
+ 'list' as ServicesViewMode,
+ {
+ setViewMode: (_, { viewMode }) => viewMode,
+ },
+ ],
page: [
1 as number,
{