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.

refactor(taxonomic-filter): extract apmTaxonomicGroupsLogic (#59823)

Paul D'Ambra29e141863c52
diff --git a/frontend/src/lib/components/TaxonomicFilter/apmTaxonomicGroupsLogic.ts b/frontend/src/lib/components/TaxonomicFilter/apmTaxonomicGroupsLogic.ts
new file mode 100644
index 000000000000..611bed861f36
--- /dev/null
+++ b/frontend/src/lib/components/TaxonomicFilter/apmTaxonomicGroupsLogic.ts
@@ -0,0 +1,172 @@
+import { connect, kea, key, path, props, selectors } from 'kea'
+import { combineUrl } from 'kea-router'
+
+import {
+ SimpleOption,
+ TaxonomicFilterGroup,
+ TaxonomicFilterGroupType,
+ TaxonomicFilterLogicProps,
+} from 'lib/components/TaxonomicFilter/types'
+import { projectLogic } from 'scenes/projectLogic'
+
+import type { apmTaxonomicGroupsLogicType } from './apmTaxonomicGroupsLogicType'
+
+export const apmTaxonomicGroupsLogic = kea<apmTaxonomicGroupsLogicType>([
+ props({} as TaxonomicFilterLogicProps),
+ key((props) => `${props.taxonomicFilterLogicKey}`),
+ path((key) => ['lib', 'components', 'TaxonomicFilter', 'apmTaxonomicGroupsLogic', key]),
+
+ connect(() => ({
+ values: [projectLogic, ['currentProjectId']],
+ })),
+
+ selectors({
+ endpointFilters: [
+ () => [(_, props) => props.endpointFilters],
+ (endpointFilters: Record<string, any>) => endpointFilters,
+ ],
+ apmTaxonomicGroups: [
+ (s) => [s.currentProjectId, s.endpointFilters],
+ (projectId, endpointFilters: Record<string, any> | undefined): TaxonomicFilterGroup[] => [
+ {
+ name: 'Logs',
+ searchPlaceholder: 'logs',
+ type: TaxonomicFilterGroupType.Logs,
+ options: [
+ { key: 'message', name: 'message', propertyFilterType: 'log' },
+ { key: 'severity_level', name: 'severity_level', propertyFilterType: 'log' },
+ { key: 'trace_id', name: 'trace_id', propertyFilterType: 'log' },
+ { key: 'span_id', name: 'span_id', propertyFilterType: 'log' },
+ ],
+ localItemsSearch: (items: any[], q: string): any[] => {
+ if (!q) {
+ return items
+ }
+ return [
+ {
+ key: 'message',
+ name: 'Search log message for "' + q + '"',
+ value: q,
+ propertyFilterType: 'log',
+ },
+ ].concat(items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase())))
+ },
+ getName: (option: { key: string; name: string }) => option.name,
+ getValue: (option: { key: string; name: string }) => option.key,
+ getPopoverHeader: () => 'Log attributes',
+ },
+ {
+ name: 'Log attributes',
+ searchPlaceholder: 'attributes',
+ type: TaxonomicFilterGroupType.LogAttributes,
+ endpoint: combineUrl(`api/environments/${projectId}/logs/attributes`, {
+ attribute_type: 'log',
+ search_values: 'true',
+ ...endpointFilters,
+ }).url,
+ valuesEndpoint: (key) =>
+ combineUrl(`api/environments/${projectId}/logs/values`, {
+ attribute_type: 'log',
+ key: key,
+ ...endpointFilters,
+ }).url,
+ getName: (option: SimpleOption) => option.name,
+ getValue: (option: SimpleOption) => option.name,
+ getPopoverHeader: () => 'Log attributes',
+ },
+ {
+ name: 'Resource attributes',
+ searchPlaceholder: 'resources',
+ type: TaxonomicFilterGroupType.LogResourceAttributes,
+ endpoint: combineUrl(`api/environments/${projectId}/logs/attributes`, {
+ attribute_type: 'resource',
+ search_values: 'true',
+ ...endpointFilters,
+ }).url,
+ valuesEndpoint: (key) =>
+ combineUrl(`api/environments/${projectId}/logs/values`, {
+ attribute_type: 'resource',
+ key: key,
+ ...endpointFilters,
+ }).url,
+ getName: (option: SimpleOption) => option.name,
+ getValue: (option: SimpleOption) => option.name,
+ getPopoverHeader: () => 'Resource attributes',
+ },
+ {
+ name: 'Spans',
+ searchPlaceholder: 'spans',
+ type: TaxonomicFilterGroupType.Spans,
+ options: [
+ { key: 'name', name: 'name', propertyFilterType: 'span' },
+ { key: 'kind', name: 'kind', propertyFilterType: 'span' },
+ { key: 'duration', name: 'duration (ms)', propertyFilterType: 'span' },
+ { key: 'trace_id', name: 'trace_id', propertyFilterType: 'span' },
+ { key: 'span_id', name: 'span_id', propertyFilterType: 'span' },
+ { key: 'status_code', name: 'status code', propertyFilterType: 'span' },
+ ],
+ valuesEndpoint: (key) =>
+ key === 'name'
+ ? combineUrl(`api/environments/${projectId}/tracing/spans/values`, {
+ attribute_type: 'span',
+ key: key,
+ ...endpointFilters,
+ }).url
+ : undefined,
+ localItemsSearch: (items: any[], q: string): any[] => {
+ if (!q) {
+ return items
+ }
+ return [
+ {
+ key: 'message',
+ name: 'Search span message for "' + q + '"',
+ value: q,
+ propertyFilterType: 'span',
+ },
+ ].concat(items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase())))
+ },
+ getName: (option: { key: string; name: string }) => option.name,
+ getValue: (option: { key: string; name: string }) => option.key,
+ getPopoverHeader: () => 'Span attributes',
+ },
+ {
+ name: 'Span attributes',
+ searchPlaceholder: 'span attributes',
+ type: TaxonomicFilterGroupType.SpanAttributes,
+ endpoint: combineUrl(`api/environments/${projectId}/tracing/spans/attributes`, {
+ attribute_type: 'span_attribute',
+ ...endpointFilters,
+ }).url,
+ valuesEndpoint: (key) =>
+ combineUrl(`api/environments/${projectId}/tracing/spans/values`, {
+ attribute_type: 'span_attribute',
+ key: key,
+ ...endpointFilters,
+ }).url,
+ getName: (option: SimpleOption) => option.name,
+ getValue: (option: SimpleOption) => option.name,
+ getPopoverHeader: () => 'Span attributes',
+ },
+ {
+ name: 'Span resource attributes',
+ searchPlaceholder: 'span resources',
+ type: TaxonomicFilterGroupType.SpanResourceAttributes,
+ endpoint: combineUrl(`api/environments/${projectId}/tracing/spans/attributes`, {
+ attribute_type: 'span_resource_attribute',
+ ...endpointFilters,
+ }).url,
+ valuesEndpoint: (key) =>
+ combineUrl(`api/environments/${projectId}/tracing/spans/values`, {
+ attribute_type: 'span_resource_attribute',
+ key: key,
+ ...endpointFilters,
+ }).url,
+ getName: (option: SimpleOption) => option.name,
+ getValue: (option: SimpleOption) => option.name,
+ getPopoverHeader: () => 'Span resource attributes',
+ },
+ ],
+ ],
+ }),
+])
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index fa31ca11a78b..9198e823baae 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -99,6 +99,7 @@ import { joinsLogic } from 'products/data_warehouse/frontend/shared/logics/joins
import { HogFlowTaxonomicFilters } from 'products/workflows/frontend/Workflows/hogflows/filters/HogFlowTaxonomicFilters'
import { PROPERTY_FILTER_TYPE_TO_TAXONOMIC_FILTER_GROUP_TYPE } from '../PropertyFilters/utils'
+import { apmTaxonomicGroupsLogic } from './apmTaxonomicGroupsLogic'
import { cohortTaxonomicGroupsLogic } from './cohortTaxonomicGroupsLogic'
import { eventMetadataTaxonomicGroupsLogic } from './eventMetadataTaxonomicGroupsLogic'
import { groupAnalyticsTaxonomicGroupsLogic } from './groupAnalyticsTaxonomicGroupsLogic'
@@ -338,6 +339,8 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
['maxAIContextTaxonomicGroups'],
suggestedFiltersTaxonomicGroupsLogic,
['suggestedFiltersTaxonomicGroups'],
+ apmTaxonomicGroupsLogic,
+ ['apmTaxonomicGroups'],
],
actions: [primaryEventPropertiesModel, ['ensureLoadedForEvents']],
})),
@@ -523,10 +526,6 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
() => [(_, props) => props.hideBehavioralCohorts],
(hideBehavioralCohorts: boolean | undefined) => hideBehavioralCohorts ?? false,
],
- endpointFilters: [
- () => [(_, props) => props.endpointFilters],
- (endpointFilters: Record<string, any>) => endpointFilters,
- ],
taxonomicGroups: [
(s) => [
s.currentTeam,
@@ -542,7 +541,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
s.eventMetadataTaxonomicGroups,
s.maxAIContextTaxonomicGroups,
s.cohortTaxonomicGroups,
- s.endpointFilters,
+ s.apmTaxonomicGroups,
s.featureFlags,
],
(
@@ -562,7 +561,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
eventMetadataTaxonomicGroups: TaxonomicFilterGroup[],
maxAIContextTaxonomicGroups: TaxonomicFilterGroup[],
cohortTaxonomicGroups: TaxonomicFilterGroup[],
- endpointFilters: Record<string, any> | undefined,
+ apmTaxonomicGroups: TaxonomicFilterGroup[],
featureFlags: Record<string, boolean | string | undefined>
): TaxonomicFilterGroup[] => {
const { eventNames } = eventNamesWithPrimaryProperties
@@ -879,144 +878,7 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
},
getPopoverHeader: () => 'Revenue analytics properties',
},
- {
- name: 'Logs',
- searchPlaceholder: 'logs',
- type: TaxonomicFilterGroupType.Logs,
- options: [
- { key: 'message', name: 'message', propertyFilterType: 'log' },
- { key: 'severity_level', name: 'severity_level', propertyFilterType: 'log' },
- { key: 'trace_id', name: 'trace_id', propertyFilterType: 'log' },
- { key: 'span_id', name: 'span_id', propertyFilterType: 'log' },
- ],
- localItemsSearch: (items: any[], q: string): any[] => {
- if (!q) {
- return items
- }
- return [
- {
- key: 'message',
- name: 'Search log message for "' + q + '"',
- value: q,
- propertyFilterType: 'log',
- },
- ].concat(items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase())))
- },
- getName: (option: { key: string; name: string }) => option.name,
- getValue: (option: { key: string; name: string }) => option.key,
- getPopoverHeader: () => 'Log attributes',
- },
- {
- name: 'Log attributes',
- searchPlaceholder: 'attributes',
- type: TaxonomicFilterGroupType.LogAttributes,
- endpoint: combineUrl(`api/environments/${projectId}/logs/attributes`, {
- attribute_type: 'log',
- search_values: 'true',
- ...endpointFilters,
- }).url,
- valuesEndpoint: (key) =>
- combineUrl(`api/environments/${projectId}/logs/values`, {
- attribute_type: 'log',
- key: key,
- ...endpointFilters,
- }).url,
- getName: (option: SimpleOption) => option.name,
- getValue: (option: SimpleOption) => option.name,
- getPopoverHeader: () => 'Log attributes',
- },
- {
- name: 'Resource attributes',
- searchPlaceholder: 'resources',
- type: TaxonomicFilterGroupType.LogResourceAttributes,
- endpoint: combineUrl(`api/environments/${projectId}/logs/attributes`, {
- attribute_type: 'resource',
- search_values: 'true',
- ...endpointFilters,
- }).url,
- valuesEndpoint: (key) =>
- combineUrl(`api/environments/${projectId}/logs/values`, {
- attribute_type: 'resource',
- key: key,
- ...endpointFilters,
- }).url,
- getName: (option: SimpleOption) => option.name,
- getValue: (option: SimpleOption) => option.name,
- getPopoverHeader: () => 'Resource attributes',
- },
- {
- name: 'Spans',
- searchPlaceholder: 'spans',
- type: TaxonomicFilterGroupType.Spans,
- options: [
- { key: 'name', name: 'name', propertyFilterType: 'span' },
- { key: 'kind', name: 'kind', propertyFilterType: 'span' },
- { key: 'duration', name: 'duration (ms)', propertyFilterType: 'span' },
- { key: 'trace_id', name: 'trace_id', propertyFilterType: 'span' },
- { key: 'span_id', name: 'span_id', propertyFilterType: 'span' },
- { key: 'status_code', name: 'status code', propertyFilterType: 'span' },
- ],
- valuesEndpoint: (key) =>
- key === 'name'
- ? combineUrl(`api/environments/${projectId}/tracing/spans/values`, {
- attribute_type: 'span',
- key: key,
- ...endpointFilters,
- }).url
- : undefined,
- localItemsSearch: (items: any[], q: string): any[] => {
- if (!q) {
- return items
- }
- return [
- {
- key: 'message',
- name: 'Search span message for "' + q + '"',
- value: q,
- propertyFilterType: 'span',
- },
- ].concat(items.filter((item) => item.name?.toLowerCase().includes(q.toLowerCase())))
- },
- getName: (option: { key: string; name: string }) => option.name,
- getValue: (option: { key: string; name: string }) => option.key,
- getPopoverHeader: () => 'Span attributes',
- },
- {
- name: 'Span attributes',
- searchPlaceholder: 'span attributes',
- type: TaxonomicFilterGroupType.SpanAttributes,
- endpoint: combineUrl(`api/environments/${projectId}/tracing/spans/attributes`, {
- attribute_type: 'span_attribute',
- ...endpointFilters,
- }).url,
- valuesEndpoint: (key) =>
- combineUrl(`api/environments/${projectId}/tracing/spans/values`, {
- attribute_type: 'span_attribute',
- key: key,
- ...endpointFilters,
- }).url,
- getName: (option: SimpleOption) => option.name,
- getValue: (option: SimpleOption) => option.name,
- getPopoverHeader: () => 'Span attributes',
- },
- {
- name: 'Span resource attributes',
- searchPlaceholder: 'span resources',
- type: TaxonomicFilterGroupType.SpanResourceAttributes,
- endpoint: combineUrl(`api/environments/${projectId}/tracing/spans/attributes`, {
- attribute_type: 'span_resource_attribute',
- ...endpointFilters,
- }).url,
- valuesEndpoint: (key) =>
- combineUrl(`api/environments/${projectId}/tracing/spans/values`, {
- attribute_type: 'span_resource_attribute',
- key: key,
- ...endpointFilters,
- }).url,
- getName: (option: SimpleOption) => option.name,
- getValue: (option: SimpleOption) => option.name,
- getPopoverHeader: () => 'Span resource attributes',
- },
+ ...apmTaxonomicGroups,
{
name: 'Numerical event properties',
searchPlaceholder: 'numerical event properties',