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 severity_level, trace_id, span_id top-level filters (#59359)

Frank Hamand9a00eff6b814
diff --git a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx
index 8c64c5822f08..6199e06a04da 100644
--- a/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx
+++ b/frontend/src/lib/components/PropertyFilters/components/OperatorValueSelect.tsx
@@ -51,6 +51,16 @@ const STATUS_CODE_OPTIONS: { key: number; label: string }[] = [
{ key: 2, label: 'Error' },
]
+// OTel severity level (https://opentelemetry.io/docs/specs/otel/logs/data-model/#field-severitynumber).
+const SEVERITY_LEVEL_OPTIONS: { key: string; label: string }[] = [
+ { key: 'trace', label: 'trace' },
+ { key: 'debug', label: 'debug' },
+ { key: 'info', label: 'info' },
+ { key: 'warn', label: 'warn' },
+ { key: 'error', label: 'error' },
+ { key: 'fatal', label: 'fatal' },
+]
+
function SpanEnumValueSelect({
options,
value,
@@ -58,7 +68,7 @@ function SpanEnumValueSelect({
isMultiSelect,
size,
}: {
- options: { key: number; label: string }[]
+ options: { key: string | number; label: string }[]
value?: PropertyFilterValue
onChange: (value: PropertyFilterValue) => void
isMultiSelect: boolean
@@ -256,8 +266,21 @@ export function OperatorValueSelect({
)
}
- // Restrict trace_id and span_id to only equals/not equals
- if ((propertyKey === 'trace_id' || propertyKey === 'span_id') && type === PropertyFilterType.Span) {
+ // Restrict trace_id, span_id, kind, and status_code to only equals/not equals
+ if (
+ propertyKey &&
+ ['trace_id', 'span_id', 'kind', 'status_code'].includes(propertyKey) &&
+ type === PropertyFilterType.Span
+ ) {
+ operators = operators.filter((op) => [PropertyOperator.Exact, PropertyOperator.IsNot].includes(op))
+ }
+
+ // Restrict log trace_id, span_id and severity_level to only equals/not equals
+ if (
+ propertyKey &&
+ ['trace_id', 'span_id', 'severity_level'].includes(propertyKey) &&
+ type === PropertyFilterType.Log
+ ) {
operators = operators.filter((op) => [PropertyOperator.Exact, PropertyOperator.IsNot].includes(op))
}
@@ -289,11 +312,6 @@ export function OperatorValueSelect({
)
}
- // Restrict span kind and status_code (fixed int enums) to equality operators
- if ((propertyKey === 'kind' || propertyKey === 'status_code') && type === PropertyFilterType.Span) {
- operators = operators.filter((op) => [PropertyOperator.Exact, PropertyOperator.IsNot].includes(op))
- }
-
setOperators(operators)
if ((currentOperator !== operator && operators.includes(startingOperator)) || !propertyDefinition) {
setCurrentOperator(startingOperator)
@@ -362,10 +380,17 @@ export function OperatorValueSelect({
className="shrink grow-[1000] min-w-[10rem] overflow-hidden"
data-attr="taxonomic-value-select"
>
- {type === PropertyFilterType.Span && (propertyKey === 'kind' || propertyKey === 'status_code') ? (
+ {(type === PropertyFilterType.Span && (propertyKey === 'kind' || propertyKey === 'status_code')) ||
+ (type === PropertyFilterType.Log && propertyKey === 'severity_level') ? (
editable ? (
<SpanEnumValueSelect
- options={propertyKey === 'kind' ? SPAN_KIND_OPTIONS : STATUS_CODE_OPTIONS}
+ options={
+ propertyKey === 'kind'
+ ? SPAN_KIND_OPTIONS
+ : propertyKey === 'status_code'
+ ? STATUS_CODE_OPTIONS
+ : SEVERITY_LEVEL_OPTIONS
+ }
value={value}
isMultiSelect={
forceSingleSelect
diff --git a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
index 018c743899c9..23d4dc598df7 100644
--- a/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/taxonomicFilterLogic.tsx
@@ -914,7 +914,12 @@ export const taxonomicFilterLogic = kea<taxonomicFilterLogicType>([
name: 'Logs',
searchPlaceholder: 'logs',
type: TaxonomicFilterGroupType.Logs,
- options: [{ key: 'message', name: 'Message', propertyFilterType: 'log' }],
+ 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
diff --git a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
index 6d40e0ff25b2..657edb44bec7 100644
--- a/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
+++ b/frontend/src/lib/components/TaxonomicFilter/utils/buildTaxonomicGroups.tsx
@@ -489,7 +489,12 @@ export function buildTaxonomicGroups(ctx: BuildTaxonomicGroupsContext): Taxonomi
name: 'Logs',
searchPlaceholder: 'logs',
type: TaxonomicFilterGroupType.Logs,
- options: [{ key: 'message', name: 'Message', propertyFilterType: 'log' }],
+ 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
diff --git a/products/logs/backend/logs_query_runner.py b/products/logs/backend/logs_query_runner.py
index ce61c4d02230..9e8d86d24d68 100644
--- a/products/logs/backend/logs_query_runner.py
+++ b/products/logs/backend/logs_query_runner.py
@@ -31,6 +31,49 @@ if TYPE_CHECKING:
from posthog.models import Team, User
+def _trace_id_normalise_to_base64(value: str) -> str:
+ """Accept either hex or base64 encoded trace_id/span_id values.
+
+ The `trace_id` and `span_id` columns store base64-encoded bytes. Hex input (32-char for
+ trace_id, 16-char for span_id) is the form users normally see in trace UIs, so we accept
+ it and convert. Values that aren't valid hex are passed through as-is (assumed base64).
+ """
+ try:
+ int(value, 16)
+ return base64.b64encode(bytes.fromhex(value)).decode()
+ except ValueError:
+ return value
+
+
+def _normalise_trace_id_filter(log_filter: LogPropertyFilter) -> None:
+ """In-place: normalize trace_id/span_id filter values to base64 to match column storage."""
+ if isinstance(log_filter.value, list):
+ log_filter.value = [_trace_id_normalise_to_base64(str(v)) for v in log_filter.value]
+ elif log_filter.value is not None:
+ log_filter.value = _trace_id_normalise_to_base64(str(log_filter.value))
+
+
+def _severity_level_to_expr(log_filter: LogPropertyFilter) -> ast.Expr:
+ """Translate a `severity_level` log property filter to a HogQL expression on `severity_text`.
+
+ Only equality operators (Exact/IsNot) are exposed in the UI.
+ """
+ values: list[str]
+ if isinstance(log_filter.value, list):
+ values = [str(v) for v in log_filter.value]
+ elif log_filter.value is None:
+ values = []
+ else:
+ values = [str(log_filter.value)]
+
+ op = ast.CompareOperationOp.NotIn if log_filter.operator == PropertyOperator.IS_NOT else ast.CompareOperationOp.In
+ return ast.CompareOperation(
+ op=op,
+ left=ast.Field(chain=["severity_text"]),
+ right=ast.Tuple(exprs=[ast.Constant(value=v) for v in values]),
+ )
+
+
def _generate_resource_attribute_filters(
resource_attribute_filters, *, existing_filters, query_date_range, team, is_negative_filter
):
@@ -246,6 +289,12 @@ class LogsFilterBuilder:
if self.log_filters:
for log_filter in self.log_filters:
+ if log_filter.key == "severity_level":
+ exprs.append(_severity_level_to_expr(log_filter))
+ continue
+ if log_filter.key in ("trace_id", "span_id"):
+ log_filter = log_filter.copy(deep=True)
+ _normalise_trace_id_filter(log_filter)
if log_filter.key == "message":
exprs.append(get_lowercase_index_hint(log_filter, team=self.team))
exprs.append(property_to_expr(log_filter, team=self.team))