Skip to content

Commit

Permalink
chore: allow log entry properties
Browse files Browse the repository at this point in the history
  • Loading branch information
daibhin committed Aug 20, 2024
1 parent 3558c9b commit 1dd5da8
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 26 deletions.
8 changes: 8 additions & 0 deletions frontend/src/lib/components/PropertyFilters/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
FilterLogicalOperator,
GroupPropertyFilter,
HogQLPropertyFilter,
LogEntryPropertyFilter,
PersonPropertyFilter,
PropertyDefinitionType,
PropertyFilterType,
Expand Down Expand Up @@ -103,6 +104,7 @@ export const PROPERTY_FILTER_TYPE_TO_TAXONOMIC_FILTER_GROUP_TYPE: Record<Propert
[PropertyFilterType.DataWarehouse]: TaxonomicFilterGroupType.DataWarehouse,
[PropertyFilterType.DataWarehousePersonProperty]: TaxonomicFilterGroupType.DataWarehousePersonProperties,
[PropertyFilterType.Recording]: TaxonomicFilterGroupType.Replay,
[PropertyFilterType.LogEntry]: TaxonomicFilterGroupType.LogEntries,
}

export function formatPropertyLabel(
Expand Down Expand Up @@ -202,6 +204,9 @@ export function isSessionPropertyFilter(filter?: AnyFilterLike | null): filter i
export function isRecordingPropertyFilter(filter?: AnyFilterLike | null): filter is RecordingPropertyFilter {
return filter?.type === PropertyFilterType.Recording
}
export function isLogEntryPropertyFilter(filter?: AnyFilterLike | null): filter is LogEntryPropertyFilter {
return filter?.type === PropertyFilterType.LogEntry
}
export function isGroupPropertyFilter(filter?: AnyFilterLike | null): filter is GroupPropertyFilter {
return filter?.type === PropertyFilterType.Group
}
Expand All @@ -223,6 +228,7 @@ export function isAnyPropertyfilter(filter?: AnyFilterLike | null): filter is An
isSessionPropertyFilter(filter) ||
isCohortPropertyFilter(filter) ||
isRecordingPropertyFilter(filter) ||
isLogEntryPropertyFilter(filter) ||
isFeaturePropertyFilter(filter) ||
isGroupPropertyFilter(filter)
)
Expand All @@ -236,6 +242,7 @@ export function isPropertyFilterWithOperator(
| ElementPropertyFilter
| SessionPropertyFilter
| RecordingPropertyFilter
| LogEntryPropertyFilter
| FeaturePropertyFilter
| GroupPropertyFilter
| DataWarehousePropertyFilter {
Expand All @@ -246,6 +253,7 @@ export function isPropertyFilterWithOperator(
isElementPropertyFilter(filter) ||
isSessionPropertyFilter(filter) ||
isRecordingPropertyFilter(filter) ||
isLogEntryPropertyFilter(filter) ||
isFeaturePropertyFilter(filter) ||
isGroupPropertyFilter(filter) ||
isDataWarehousePropertyFilter(filter))
Expand Down
1 change: 1 addition & 0 deletions frontend/src/lib/components/TaxonomicFilter/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ export enum TaxonomicFilterGroupType {
SessionProperties = 'session_properties',
HogQLExpression = 'hogql_expression',
Notebooks = 'notebooks',
LogEntries = 'log_entries',
// Misc
Replay = 'replay',
}
Expand Down
6 changes: 2 additions & 4 deletions frontend/src/lib/utils/eventUsageLogic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { BarStatus, ResultType } from 'lib/components/CommandBar/types'
import {
convertPropertyGroupToProperties,
isGroupPropertyFilter,
isRecordingPropertyFilter,
isLogEntryPropertyFilter,
isValidPropertyFilter,
} from 'lib/components/PropertyFilters/utils'
import { TaxonomicFilterGroupType } from 'lib/components/TaxonomicFilter/types'
Expand Down Expand Up @@ -930,9 +930,7 @@ export const eventUsageLogic = kea<eventUsageLogicType>([
const eventFilters = filterValues.filter(isEventFilter)
const actionFilters = filterValues.filter(isActionFilter)
const propertyFilters = filterValues.filter(isValidPropertyFilter)
const consoleLogFilters = propertyFilters
.filter(isRecordingPropertyFilter)
.filter((f) => ['console_log_level', 'console_log_query'].includes(f.key))
const consoleLogFilters = propertyFilters.filter(isLogEntryPropertyFilter)

const filterBreakdown =
filters && defaultDurationFilter
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/queries/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,9 @@
{
"$ref": "#/definitions/RecordingPropertyFilter"
},
{
"$ref": "#/definitions/LogEntryPropertyFilter"
},
{
"$ref": "#/definitions/GroupPropertyFilter"
},
Expand Down Expand Up @@ -5925,6 +5928,29 @@
"enum": ["new", "resurrecting", "returning", "dormant"],
"type": "string"
},
"LogEntryPropertyFilter": {
"additionalProperties": false,
"properties": {
"key": {
"type": "string"
},
"label": {
"type": "string"
},
"operator": {
"$ref": "#/definitions/PropertyOperator"
},
"type": {
"const": "log_entry",
"type": "string"
},
"value": {
"$ref": "#/definitions/PropertyFilterValue"
}
},
"required": ["key", "operator", "type"],
"type": "object"
},
"MathType": {
"anyOf": [
{
Expand Down Expand Up @@ -6323,6 +6349,7 @@
"session",
"cohort",
"recording",
"log_entry",
"group",
"hogql",
"data_warehouse",
Expand Down Expand Up @@ -8870,6 +8897,7 @@
"session_properties",
"hogql_expression",
"notebooks",
"log_entries",
"replay"
],
"type": "string"
Expand Down
19 changes: 17 additions & 2 deletions frontend/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,7 @@ export enum PropertyFilterType {
Session = 'session',
Cohort = 'cohort',
Recording = 'recording',
LogEntry = 'log_entry',
Group = 'group',
HogQL = 'hogql',
DataWarehouse = 'data_warehouse',
Expand Down Expand Up @@ -789,6 +790,7 @@ export type AnyPropertyFilter =
| SessionPropertyFilter
| CohortPropertyFilter
| RecordingPropertyFilter
| LogEntryPropertyFilter
| GroupPropertyFilter
| FeaturePropertyFilter
| HogQLPropertyFilter
Expand Down Expand Up @@ -970,6 +972,19 @@ export interface RecordingDurationFilter extends RecordingPropertyFilter {

export type DurationType = 'duration' | 'active_seconds' | 'inactive_seconds'

export interface LogEntryPropertyFilter extends BasePropertyFilter {
type: PropertyFilterType.LogEntry
operator: PropertyOperator
}

export interface LogEntryLevelFilter extends LogEntryPropertyFilter {
key: 'level'
value: FilterableLogLevel[]
}
export interface LogEntryMessageFilter extends LogEntryPropertyFilter {
key: 'message'
value: string
}
export type FilterableLogLevel = 'info' | 'warn' | 'error'

export interface RecordingFilters {
Expand All @@ -980,9 +995,9 @@ export interface RecordingFilters {
properties?: AnyPropertyFilter[]
session_recording_duration?: RecordingDurationFilter
duration_type_filter?: DurationType
console_search_query?: string
console_search_query?: LogEntryMessageFilter['value']
console_logs?: LogEntryLevelFilter['value']
snapshot_source?: AnyPropertyFilter | null
console_logs?: FilterableLogLevel[]
filter_test_accounts?: boolean
operand?: FilterLogicalOperator
}
Expand Down
45 changes: 25 additions & 20 deletions posthog/hogql/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
SessionPropertyFilter,
CohortPropertyFilter,
RecordingPropertyFilter,
LogEntryPropertyFilter,
GroupPropertyFilter,
FeaturePropertyFilter,
HogQLPropertyFilter,
Expand Down Expand Up @@ -247,25 +248,28 @@ def _field_to_compare_op(


def property_to_expr(
property: list
| dict
| PropertyGroup
| PropertyGroupFilter
| PropertyGroupFilterValue
| Property
| ast.Expr
| EventPropertyFilter
| PersonPropertyFilter
| ElementPropertyFilter
| SessionPropertyFilter
| CohortPropertyFilter
| RecordingPropertyFilter
| GroupPropertyFilter
| FeaturePropertyFilter
| HogQLPropertyFilter
| EmptyPropertyFilter
| DataWarehousePropertyFilter
| DataWarehousePersonPropertyFilter,
property: (
list
| dict
| PropertyGroup
| PropertyGroupFilter
| PropertyGroupFilterValue
| Property
| ast.Expr
| EventPropertyFilter
| PersonPropertyFilter
| ElementPropertyFilter
| SessionPropertyFilter
| CohortPropertyFilter
| RecordingPropertyFilter
| LogEntryPropertyFilter
| GroupPropertyFilter
| FeaturePropertyFilter
| HogQLPropertyFilter
| EmptyPropertyFilter
| DataWarehousePropertyFilter
| DataWarehousePersonPropertyFilter
),
team: Team,
scope: Literal["event", "person", "session", "replay", "replay_entity", "replay_pdi"] = "event",
) -> ast.Expr:
Expand Down Expand Up @@ -337,6 +341,7 @@ def property_to_expr(
or property.type == "data_warehouse"
or property.type == "data_warehouse_person_property"
or property.type == "session"
or property.type == "log_entry"
):
if (scope == "person" and property.type != "person") or (scope == "session" and property.type != "session"):
raise QueryError(f"The '{property.type}' property filter does not work in '{scope}' scope")
Expand All @@ -358,7 +363,7 @@ def property_to_expr(
raise QueryError("Data warehouse person property filter value must be a string")
elif property.type == "group":
chain = [f"group_{property.group_type_index}", "properties"]
elif property.type == "data_warehouse":
elif property.type in ["data_warehouse", "log_entry"]:
chain = []
elif property.type == "session" and scope in ["event", "replay"]:
chain = ["session"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
PropertyGroupFilter,
PropertyOperator,
RecordingPropertyFilter,
LogEntryPropertyFilter,
SessionPropertyFilter,
StickinessFilter,
StickinessQuery,
Expand Down Expand Up @@ -60,6 +61,7 @@ class SeriesTestData:
SessionPropertyFilter,
CohortPropertyFilter,
RecordingPropertyFilter,
LogEntryPropertyFilter,
GroupPropertyFilter,
FeaturePropertyFilter,
HogQLPropertyFilter,
Expand Down
2 changes: 2 additions & 0 deletions posthog/models/property/property.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class BehavioralPropertyType(StrEnum):
"precalculated-cohort",
"group",
"recording",
"log_entry",
"behavioral",
"session",
"hogql",
Expand Down Expand Up @@ -91,6 +92,7 @@ class BehavioralPropertyType(StrEnum):
"precalculated-cohort": ["key", "value"],
"group": ["key", "value", "group_type_index"],
"recording": ["key", "value"],
"log_entry": ["key", "value"],
"behavioral": ["key", "value"],
"session": ["key", "value"],
"hogql": ["key"],
Expand Down
Loading

0 comments on commit 1dd5da8

Please sign in to comment.