: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
feat(logs): add Logs tab to person profile + MCP prompt update (#60537)
Daniel Visca7065e1310b66
diff --git a/frontend/src/scenes/persons/PersonLogsTab.tsx b/frontend/src/scenes/persons/PersonLogsTab.tsxnew file mode 100644index 000000000000..0d694ea43c2f--- /dev/null+++ b/frontend/src/scenes/persons/PersonLogsTab.tsx@@ -0,0 +1,43 @@+import { useValues } from 'kea'+import { useMemo } from 'react'++import { FilterLogicalOperator, LogPropertyFilter, PersonType, PropertyFilterType, PropertyOperator } from '~/types'++import { LogsViewer } from 'products/logs/frontend/components/LogsViewer/LogsViewer'+import { DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY, logsConfigLogic } from 'products/logs/frontend/logsConfigLogic'++// Renders the Logs tab on the person profile. Mounted only when the tab is active+// (LemonTabs renders just the active tab's content), so `logsConfigLogic` only fetches+// the team's `logs_distinct_id_attribute_key` on demand rather than on every team load.+// While the config loads, falls back to the default key — accurate for the vast majority+// of teams; non-default teams briefly see the wrong filter then resolve to the override.+export function PersonLogsTab({ person }: { person: PersonType }): JSX.Element {+ const { logsConfig } = useValues(logsConfigLogic)+ const distinctIdAttributeKey = logsConfig?.logs_distinct_id_attribute_key ?? DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY++ const pinnedFilters = useMemo(+ () => ({+ type: FilterLogicalOperator.And,+ values: [+ {+ key: distinctIdAttributeKey,+ type: PropertyFilterType.LogAttribute,+ operator: PropertyOperator.Exact,+ value: person.distinct_ids,+ } as LogPropertyFilter,+ ],+ }),+ [distinctIdAttributeKey, person.distinct_ids]+ )++ return (+ <div className="flex flex-col h-[calc(100vh-16rem)] min-h-[25rem]">+ <LogsViewer+ id={`person-${person.uuid ?? person.id}`}+ pinnedFilters={pinnedFilters}+ showFullScreenButton={false}+ showSavedViewsButton={false}+ />+ </div>+ )+}diff --git a/frontend/src/scenes/persons/PersonScene.tsx b/frontend/src/scenes/persons/PersonScene.tsxindex 57824bf2c0a3..b406a4ba4813 100644--- a/frontend/src/scenes/persons/PersonScene.tsx+++ b/frontend/src/scenes/persons/PersonScene.tsx@@ -45,6 +45,7 @@ import { FeedbackButton } from 'products/customer_analytics/frontend/components/import { MergeSplitPerson } from './MergeSplitPerson'import { asDisplay } from './person-utils'import { PersonCohorts } from './PersonCohorts'+import { PersonLogsTab } from './PersonLogsTab'import PersonProfileCanvas from './PersonProfileCanvas'import { PERSON_EVENTS_CONTEXT_KEY, PersonsLogicProps, personsLogic } from './personsLogic'import { RelatedFeatureFlags } from './RelatedFeatureFlags'@@ -370,6 +371,11 @@ export function PersonScene({ tabId }: { tabId?: string }): JSX.Element | null {</>),},+ {+ key: PersonsTabType.LOGS,+ label: <span data-attr="persons-logs-tab">Logs</span>,+ content: <PersonLogsTab person={person} />,+ },{key: PersonsTabType.EXCEPTIONS,label: <span data-attr="persons-exceptions-tab">Exceptions</span>,diff --git a/frontend/src/types.ts b/frontend/src/types.tsindex 45b22e89e2f7..d9c57d49f945 100644--- a/frontend/src/types.ts+++ b/frontend/src/types.ts@@ -1715,6 +1715,7 @@ export enum PersonsTabType {EXCEPTIONS = 'exceptions',SURVEY_RESPONSES = 'surveyResponses',SESSION_RECORDINGS = 'sessionRecordings',+ LOGS = 'logs',PROPERTIES = 'properties',COHORTS = 'cohorts',RELATED = 'related',diff --git a/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsx b/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsxindex 804921f96f4f..830cfd7d5fd0 100644--- a/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsx+++ b/products/logs/frontend/components/LogsViewer/Filters/LogsFilterBar/LogsFilterBar.tsx@@ -1,5 +1,6 @@import './LogsFilterBar.scss'+import equal from 'fast-deep-equal'import { BindLogic, useActions, useValues } from 'kea'import { useRef, useState } from 'react'@@ -226,6 +227,7 @@ const LogsFilterSearch = (): JSX.Element => {const FilterGroupValues = ({ allowInitiallyOpen }: { allowInitiallyOpen: boolean }): JSX.Element | null => {const { filterGroup } = useValues(universalFiltersLogic)const { replaceGroupValue, removeGroupValue } = useActions(universalFiltersLogic)+ const { pinnedFilters } = useValues(logsViewerFiltersLogic)if (filterGroup.values.length === 0) {return null@@ -234,6 +236,14 @@ const FilterGroupValues = ({ allowInitiallyOpen }: { allowInitiallyOpen: booleanreturn (<>{filterGroup.values.map((filterOrGroup, index) => {+ // Pinned filters are enforced by the embedding scene (e.g. distinct_id+ // scope on a person profile). They're applied to the query but hidden+ // from the chip list — matching how Events / Exceptions hide their+ // structural person scope. Without this, a user could click in and+ // edit values that conceptually shouldn't be theirs to edit.+ if (pinnedFilters?.values.some((pv) => equal(pv, filterOrGroup))) {+ return null+ }return isUniversalGroupFilterLike(filterOrGroup) ? (<UniversalFilters.Group index={index} key={index} group={filterOrGroup}><FilterGroupValues allowInitiallyOpen={allowInitiallyOpen} />diff --git a/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.ts b/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.tsindex b7d80f29971e..ab032b498135 100644--- a/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.ts+++ b/products/logs/frontend/components/LogsViewer/Filters/logsViewerFiltersLogic.ts@@ -1,3 +1,4 @@+import equal from 'fast-deep-equal'import { actions, afterMount, kea, key, listeners, path, propsChanged, props, reducers, selectors } from 'kea'import posthog from 'posthog-js'@@ -5,7 +6,13 @@ import { DEFAULT_UNIVERSAL_GROUP_FILTER } from 'lib/components/UniversalFilters/import { dayjs } from 'lib/dayjs'import { DateRange, LogSeverityLevel, LogsQuery } from '~/queries/schema/schema-general'-import { PropertyFilterType, PropertyOperator, UniversalFiltersGroup, UniversalFiltersGroupValue } from '~/types'+import {+ FilterLogicalOperator,+ PropertyFilterType,+ PropertyOperator,+ UniversalFiltersGroup,+ UniversalFiltersGroupValue,+} from '~/types'import { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'import { zoomDateRange } from 'products/logs/frontend/components/LogsViewer/Filters/zoom-utils'@@ -24,6 +31,34 @@ export const DEFAULT_SERVICE_NAMES = [] as LogsQuery['serviceNames']export interface LogsViewerFiltersLogicProps {id: stringinitialFilters?: Partial<LogsViewerFilters>+ // Filters enforced by the embedding scene. Merged into filterGroup and rendered+ // without an X — users can't accidentally clear the scope (e.g. the person profile+ // Logs tab pins a distinct_id filter so the tab can't fall back to project-wide logs).+ pinnedFilters?: UniversalFiltersGroup+}++// Returns a filterGroup with pinned values prepended to the nested group, deduplicated+// by deep equality against existing user filters.+export function mergePinnedFilters(+ filterGroup: UniversalFiltersGroup,+ pinnedFilters: UniversalFiltersGroup | undefined+): UniversalFiltersGroup {+ if (!pinnedFilters?.values?.length) {+ return filterGroup+ }+ const inner = filterGroup.values[0] as UniversalFiltersGroup | undefined+ const innerValues = inner?.values ?? []+ const existingNonPinned = innerValues.filter((v) => !pinnedFilters.values.some((pv) => equal(v, pv)))+ return {+ ...filterGroup,+ values: [+ {+ type: FilterLogicalOperator.And,+ values: [...pinnedFilters.values, ...existingNonPinned],+ } as UniversalFiltersGroup,+ ...filterGroup.values.slice(1),+ ],+ }}export const logsViewerFiltersLogic = kea<logsViewerFiltersLogicType>([@@ -48,6 +83,11 @@ export const logsViewerFiltersLogic = kea<logsViewerFiltersLogicType>([pushToHistory,}),+ // Mirror of the `pinnedFilters` prop into state so consumers (LogsFilterBar)+ // can read it via useValues without going through the kea selector input-prop+ // machinery (which doesn't accept optional props).+ setPinnedFilters: (pinnedFilters: UniversalFiltersGroup | undefined) => ({ pinnedFilters }),+zoomDateRange: (multiplier: number) => ({ multiplier }),addFilter: (@@ -107,6 +147,12 @@ export const logsViewerFiltersLogic = kea<logsViewerFiltersLogicType>([setFilterGroup: (_, { openFilterOnInsert }) => openFilterOnInsert,},],+ pinnedFilters: [+ undefined as UniversalFiltersGroup | undefined,+ {+ setPinnedFilters: (_, { pinnedFilters }) => pinnedFilters,+ },+ ],}),selectors({@@ -164,7 +210,7 @@ export const logsViewerFiltersLogic = kea<logsViewerFiltersLogicType>([},})),- propsChanged(({ actions, props: logicProps }, oldProps) => {+ propsChanged(({ actions, values, props: logicProps }, oldProps) => {if (logicProps.initialFilters && logicProps.initialFilters !== oldProps.initialFilters) {actions.setFilters(logicProps.initialFilters, false)} else if (!logicProps.initialFilters && oldProps.initialFilters) {@@ -177,11 +223,22 @@ export const logsViewerFiltersLogic = kea<logsViewerFiltersLogicType>([false)}+ // Re-merge pinned filters when the embedding scene changes them (e.g. switching+ // between people on the person profile). Deep-equal check avoids re-merging on+ // every render when the parent reconstructs the prop object identically.+ if (!equal(logicProps.pinnedFilters, oldProps.pinnedFilters)) {+ actions.setPinnedFilters(logicProps.pinnedFilters)+ actions.setFilterGroup(mergePinnedFilters(values.filterGroup, logicProps.pinnedFilters), false)+ }}),- afterMount(({ actions, props: logicProps }) => {+ afterMount(({ actions, values, props: logicProps }) => {if (logicProps.initialFilters) {actions.setFilters(logicProps.initialFilters, false)}+ if (logicProps.pinnedFilters) {+ actions.setPinnedFilters(logicProps.pinnedFilters)+ actions.setFilterGroup(mergePinnedFilters(values.filterGroup, logicProps.pinnedFilters), false)+ }}),])diff --git a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx b/products/logs/frontend/components/LogsViewer/LogsViewer.tsxindex dbfd0b8b3098..9777c49d3f5c 100644--- a/products/logs/frontend/components/LogsViewer/LogsViewer.tsx+++ b/products/logs/frontend/components/LogsViewer/LogsViewer.tsx@@ -5,6 +5,7 @@ import { TZLabelProps } from 'lib/components/TZLabel'import { useKeyboardHotkeys } from 'lib/hooks/useKeyboardHotkeys'import { SceneDivider } from '~/layout/scenes/components/SceneDivider'+import { UniversalFiltersGroup } from '~/types'import { logsViewerConfigLogic } from 'products/logs/frontend/components/LogsViewer/config/logsViewerConfigLogic'import { LogsViewerFilters } from 'products/logs/frontend/components/LogsViewer/config/types'@@ -31,6 +32,9 @@ export interface LogsViewerProps {showFullScreenButton?: booleanshowSavedViewsButton?: booleaninitialFilters?: Partial<LogsViewerFilters>+ // Filters enforced by the embedding scene. Merged into the user-editable filterGroup+ // and rendered without an X so users can't accidentally drop the scope.+ pinnedFilters?: UniversalFiltersGroup}export function LogsViewer({@@ -38,9 +42,10 @@ export function LogsViewer({showFullScreenButton = true,showSavedViewsButton = false,initialFilters,+ pinnedFilters,}: LogsViewerProps): JSX.Element {return (- <BindLogic logic={logsViewerFiltersLogic} props={{ id, initialFilters }}>+ <BindLogic logic={logsViewerFiltersLogic} props={{ id, initialFilters, pinnedFilters }}><BindLogic logic={logsViewerConfigLogic} props={{ id }}><BindLogic logic={logsViewerDataLogic} props={{ id }}><BindLogic logic={logDetailsModalLogic} props={{ id }}>diff --git a/products/logs/frontend/logsConfigLogic.ts b/products/logs/frontend/logsConfigLogic.tsnew file mode 100644index 000000000000..14d2910d1d34--- /dev/null+++ b/products/logs/frontend/logsConfigLogic.ts@@ -0,0 +1,40 @@+import { afterMount, connect, kea, path } from 'kea'+import { loaders } from 'kea-loaders'++import api from 'lib/api'+import { teamLogic } from 'scenes/teamLogic'++import type { logsConfigLogicType } from './logsConfigLogicType'++// Mirrors the backend default in products/logs/backend/models.py — the convention+// documented at https://posthog.com/docs/logs/link-session-replay. Used as the+// pre-load fallback in `PersonLogsTab` so the initial pinned filter matches the+// SDK convention before `logs_config` resolves.+export const DEFAULT_LOGS_DISTINCT_ID_ATTRIBUTE_KEY = 'posthogDistinctId'++export interface LogsConfig {+ logs_distinct_id_attribute_key: string+}++export const logsConfigLogic = kea<logsConfigLogicType>([+ path(['products', 'logs', 'frontend', 'logsConfigLogic']),+ connect({ values: [teamLogic, ['currentTeamId']] }),+ loaders(({ values }) => ({+ logsConfig: [+ null as LogsConfig | null,+ {+ loadLogsConfig: async (): Promise<LogsConfig> => {+ // The `logs_config` sub-endpoint is a `@action` on TeamViewSet without+ // `@extend_schema`, so it isn't in the generated client (same as+ // `experiments_config`). The codegen path opens up when the action+ // gets a proper request/response schema annotation.+ // nosemgrep: prefer-codegen-api+ return await api.get(`api/environments/${values.currentTeamId}/logs_config/`)+ },+ },+ ],+ })),+ afterMount(({ actions }) => {+ actions.loadLogsConfig()+ }),+])diff --git a/products/logs/mcp/prompts/query-logs.md b/products/logs/mcp/prompts/query-logs.mdindex 84152a57fc02..48274e452aaf 100644--- a/products/logs/mcp/prompts/query-logs.md+++ b/products/logs/mcp/prompts/query-logs.md@@ -46,6 +46,30 @@ Supported operators:The `value` field accepts a string, number, or array of strings depending on the operator. Omit `value` for `is_set`/`is_not_set`.+## Filtering logs by a PostHog person++When the user references a person — by `distinct_id`, name, email, or via a prior `persons-retrieve` call — filter logs to that person via a `log_attribute` filter. The attribute key is configurable per project (it defaults to `distinct_id`); read `logs_distinct_id_attribute_key` from the team config (returned on `projects-retrieve` / `environments-retrieve`, or via the `/api/projects/:id/logs_config/` endpoint) and use that as the filter `key`.++If the team has not configured a custom key, use `distinct_id`. If a person has multiple `distinct_ids`, pass the array as the filter `value` with operator `exact` (matches any of them).++```json+{+ "query": {+ "serviceNames": ["<service>"],+ "filterGroup": [+ {+ "key": "distinct_id",+ "operator": "exact",+ "type": "log_attribute",+ "value": ["<distinct_id_1>", "<distinct_id_2>"]+ }+ ]+ }+}+```++Do not invent a different attribute key based on what looks plausible — use the configured key. If the configured key returns zero results, the customer's logs pipeline may not stamp person identity at all; tell the user rather than guessing.+## Time periodUse the `query.dateRange` field to control the time window. If the question doesn't mention time, the default is the last hour (`-1h`). Examples of relative dates: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.diff --git a/services/mcp/schema/generated-tool-definitions.json b/services/mcp/schema/generated-tool-definitions.jsonindex 0bb06e361eb9..ada44f12b94c 100644--- a/services/mcp/schema/generated-tool-definitions.json+++ b/services/mcp/schema/generated-tool-definitions.json@@ -4432,7 +4432,7 @@"system_prompt_hint": "LLM/AI trace listing and inspection"},"query-logs": {- "description": "Query log entries with filtering by severity, service name, date range, search term, and structured attribute filters. Supports cursor-based pagination. The response schema (see the tool's typed output) lists every returned field — prefer `severity_text` over `severity_number` / `level`, and be aware that `trace_id` and `span_id` return zero-padded strings rather than null when unset.\n\nUse `logs-attributes-list` and `logs-attribute-values-list` to discover available attributes before building filters.\n\n# Workflow — follow this order every time\n\n1. **Discover services first.** Call `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to see available services.\n2. **Explore resource attributes.** Call `logs-attributes-list` with `attribute_type: \"resource\"` to discover resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`). Then call `logs-attribute-values-list` with `attribute_type: \"resource\"` for relevant attributes to validate what data exists.\n3. **Explore log attributes if needed.** Call `logs-attributes-list` (defaults to log attributes) and `logs-attribute-values-list` to discover log-level attributes.\n4. **Size the total volume with `logs-count`.** Call `logs-count` with the discovered `serviceNames` and filters. If it exceeds `query-logs`'s max `limit` of 1000 — or if the user's question is about _when_ something happened — continue to step 5.\n5. **Find where the volume sits with `logs-count-ranges`.** Call `logs-count-ranges` to get time-bucketed counts. Each bucket carries explicit `date_from`/`date_to` you can pass straight back as the next call's `dateRange` to drill into a sub-range. Recurse up to 3–4 levels to narrow onto a spike or a specific window. Stop when the bucket width drops below your precision goal (e.g. 1 minute).\n6. **Only then query logs.** Once the count is in range and the window is right-sized, call `query-logs` with `serviceNames` and any additional filters.\n\nMany cheap calls (attribute/value queries, counts, count-ranges) beat one expensive `query-logs`. Prefer thorough exploration over speculative log searches.\n\nCRITICAL: Be minimalist. Only include filters and settings that are essential to answer the user's specific question. Default settings are usually sufficient unless the user explicitly requests customization.\n\nMANDATORY: Never call query-logs without setting `serviceNames` or at least one `log_resource_attribute` filter. Unfiltered log queries are too broad, expensive, and noisy. If the user hasn't specified a service, use the workflow above to discover services first, then ask or infer.\n\nAll parameters must be nested inside a `query` object.\n\n# Data narrowing\n\n## Property filters\n\nUse property filters via the `query.filterGroup` field to narrow results. Only include property filters when they are essential to directly answer the user's question.\n\nWhen using a property filter, you should:\n\n- **Choose the right type.** Log property types are:\n - `log` — filters the log body/message. Use key \"message\" for this type.\n - `log_attribute` — filters log-level attributes (e.g. \"k8s.container.name\", \"http.method\").\n - `log_resource_attribute` — filters resource-level attributes (e.g. k8s labels, deployment info).\n- **Use `logs-attributes-list` to discover available attribute keys** before building filters.\n- **Use `logs-attribute-values-list` to discover valid values** for a specific attribute key.\n- **Find the suitable operator for the value type** (see supported operators below).\n\n**Important:** The `logs-attributes-list` and `logs-attribute-values-list` tools default to `attribute_type: \"log\"` (log-level attributes). To search resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`), you must explicitly pass `attribute_type: \"resource\"`. Forgetting this will return log-level attributes when you intended resource-level ones.\n\nSupported operators:\n\n- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`\n- Numeric: `exact`, `gt`, `lt`\n- Date: `is_date_exact`, `is_date_before`, `is_date_after`\n- Existence (no value needed): `is_set`, `is_not_set`\n\nThe `value` field accepts a string, number, or array of strings depending on the operator. Omit `value` for `is_set`/`is_not_set`.\n\n## Time period\n\nUse the `query.dateRange` field to control the time window. If the question doesn't mention time, the default is the last hour (`-1h`). Examples of relative dates: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.severityLevels\n\nFilter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels.\n\n## query.serviceNames\n\nFilter by service names. Use `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to discover available services.\n\n## query.searchTerm\n\nFull-text search across log bodies. Use this when the user is looking for specific text in log messages.\n\n## query.orderBy\n\nSort by timestamp: `latest` (default) or `earliest`.\n\n## query.filterGroup\n\nA list of property filters to narrow results. Each filter specifies `key`, `operator`, `type` (log/log_attribute/log_resource_attribute), and optionally `value`. See the \"Property filters\" section above.\n\n## query.dateRange\n\nDate range to filter results. Defaults to the last hour (`-1h`).\n\n- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.limit\n\nMaximum number of results (1-1000). Defaults to 100.\n\n## query.after\n\nCursor for pagination. Use the `nextCursor` value from the previous response.\n\n# Examples\n\n## List recent error logs\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\", \"fatal\"],\n \"serviceNames\": [\"<service>\"]\n }\n}\n```\n\n## Search for a specific log message\n\n```json\n{\n \"query\": {\n \"searchTerm\": \"connection refused\",\n \"serviceNames\": [\"<service>\"],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Filter logs from a specific service\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Filter by a log attribute\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"http.status_code\", \"operator\": \"exact\", \"type\": \"log_attribute\", \"value\": \"500\" }],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Combine severity and attribute filters\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\"],\n \"filterGroup\": [\n { \"key\": \"k8s.container.name\", \"operator\": \"exact\", \"type\": \"log_resource_attribute\", \"value\": \"web\" }\n ],\n \"dateRange\": { \"date_from\": \"-12h\" }\n }\n}\n```\n\n## Filter by log body content using property filter\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"message\", \"operator\": \"icontains\", \"type\": \"log\", \"value\": \"timeout\" }]\n }\n}\n```\n\n## Check if an attribute exists\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"trace_id\", \"operator\": \"is_set\", \"type\": \"log_attribute\" }]\n }\n}\n```\n\n# Reminders\n\n- Always set `serviceNames` or a resource attribute filter. Never run a broad unfiltered log query.\n- Limit `dateRange` to at most `-1d` (24 hours) unless the user explicitly requests a longer range.\n- When using `logs-attributes-list` or `logs-attribute-values-list`, remember they default to `attribute_type: \"log\"`. Pass `attribute_type: \"resource\"` to search resource-level attributes.\n- Ensure that any property filters are directly relevant to the user's question. Avoid unnecessary filtering.\n- Use `logs-attributes-list` and `logs-attribute-values-list` to discover attributes before guessing filter keys/values.\n- Prefer `searchTerm` for simple text matching; use `filterGroup` with type `log` and key `message` for regex or exact matching.",+ "description": "Query log entries with filtering by severity, service name, date range, search term, and structured attribute filters. Supports cursor-based pagination. The response schema (see the tool's typed output) lists every returned field — prefer `severity_text` over `severity_number` / `level`, and be aware that `trace_id` and `span_id` return zero-padded strings rather than null when unset.\n\nUse `logs-attributes-list` and `logs-attribute-values-list` to discover available attributes before building filters.\n\n# Workflow — follow this order every time\n\n1. **Discover services first.** Call `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to see available services.\n2. **Explore resource attributes.** Call `logs-attributes-list` with `attribute_type: \"resource\"` to discover resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`). Then call `logs-attribute-values-list` with `attribute_type: \"resource\"` for relevant attributes to validate what data exists.\n3. **Explore log attributes if needed.** Call `logs-attributes-list` (defaults to log attributes) and `logs-attribute-values-list` to discover log-level attributes.\n4. **Size the total volume with `logs-count`.** Call `logs-count` with the discovered `serviceNames` and filters. If it exceeds `query-logs`'s max `limit` of 1000 — or if the user's question is about _when_ something happened — continue to step 5.\n5. **Find where the volume sits with `logs-count-ranges`.** Call `logs-count-ranges` to get time-bucketed counts. Each bucket carries explicit `date_from`/`date_to` you can pass straight back as the next call's `dateRange` to drill into a sub-range. Recurse up to 3–4 levels to narrow onto a spike or a specific window. Stop when the bucket width drops below your precision goal (e.g. 1 minute).\n6. **Only then query logs.** Once the count is in range and the window is right-sized, call `query-logs` with `serviceNames` and any additional filters.\n\nMany cheap calls (attribute/value queries, counts, count-ranges) beat one expensive `query-logs`. Prefer thorough exploration over speculative log searches.\n\nCRITICAL: Be minimalist. Only include filters and settings that are essential to answer the user's specific question. Default settings are usually sufficient unless the user explicitly requests customization.\n\nMANDATORY: Never call query-logs without setting `serviceNames` or at least one `log_resource_attribute` filter. Unfiltered log queries are too broad, expensive, and noisy. If the user hasn't specified a service, use the workflow above to discover services first, then ask or infer.\n\nAll parameters must be nested inside a `query` object.\n\n# Data narrowing\n\n## Property filters\n\nUse property filters via the `query.filterGroup` field to narrow results. Only include property filters when they are essential to directly answer the user's question.\n\nWhen using a property filter, you should:\n\n- **Choose the right type.** Log property types are:\n - `log` — filters the log body/message. Use key \"message\" for this type.\n - `log_attribute` — filters log-level attributes (e.g. \"k8s.container.name\", \"http.method\").\n - `log_resource_attribute` — filters resource-level attributes (e.g. k8s labels, deployment info).\n- **Use `logs-attributes-list` to discover available attribute keys** before building filters.\n- **Use `logs-attribute-values-list` to discover valid values** for a specific attribute key.\n- **Find the suitable operator for the value type** (see supported operators below).\n\n**Important:** The `logs-attributes-list` and `logs-attribute-values-list` tools default to `attribute_type: \"log\"` (log-level attributes). To search resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`), you must explicitly pass `attribute_type: \"resource\"`. Forgetting this will return log-level attributes when you intended resource-level ones.\n\nSupported operators:\n\n- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`\n- Numeric: `exact`, `gt`, `lt`\n- Date: `is_date_exact`, `is_date_before`, `is_date_after`\n- Existence (no value needed): `is_set`, `is_not_set`\n\nThe `value` field accepts a string, number, or array of strings depending on the operator. Omit `value` for `is_set`/`is_not_set`.\n\n## Filtering logs by a PostHog person\n\nWhen the user references a person — by `distinct_id`, name, email, or via a prior `persons-retrieve` call — filter logs to that person via a `log_attribute` filter. The attribute key is configurable per project (it defaults to `distinct_id`); read `logs_distinct_id_attribute_key` from the team config (returned on `projects-retrieve` / `environments-retrieve`, or via the `/api/projects/:id/logs_config/` endpoint) and use that as the filter `key`.\n\nIf the team has not configured a custom key, use `distinct_id`. If a person has multiple `distinct_ids`, pass the array as the filter `value` with operator `exact` (matches any of them).\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [\n {\n \"key\": \"distinct_id\",\n \"operator\": \"exact\",\n \"type\": \"log_attribute\",\n \"value\": [\"<distinct_id_1>\", \"<distinct_id_2>\"]\n }\n ]\n }\n}\n```\n\nDo not invent a different attribute key based on what looks plausible — use the configured key. If the configured key returns zero results, the customer's logs pipeline may not stamp person identity at all; tell the user rather than guessing.\n\n## Time period\n\nUse the `query.dateRange` field to control the time window. If the question doesn't mention time, the default is the last hour (`-1h`). Examples of relative dates: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.severityLevels\n\nFilter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels.\n\n## query.serviceNames\n\nFilter by service names. Use `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to discover available services.\n\n## query.searchTerm\n\nFull-text search across log bodies. Use this when the user is looking for specific text in log messages.\n\n## query.orderBy\n\nSort by timestamp: `latest` (default) or `earliest`.\n\n## query.filterGroup\n\nA list of property filters to narrow results. Each filter specifies `key`, `operator`, `type` (log/log_attribute/log_resource_attribute), and optionally `value`. See the \"Property filters\" section above.\n\n## query.dateRange\n\nDate range to filter results. Defaults to the last hour (`-1h`).\n\n- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.limit\n\nMaximum number of results (1-1000). Defaults to 100.\n\n## query.after\n\nCursor for pagination. Use the `nextCursor` value from the previous response.\n\n# Examples\n\n## List recent error logs\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\", \"fatal\"],\n \"serviceNames\": [\"<service>\"]\n }\n}\n```\n\n## Search for a specific log message\n\n```json\n{\n \"query\": {\n \"searchTerm\": \"connection refused\",\n \"serviceNames\": [\"<service>\"],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Filter logs from a specific service\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Filter by a log attribute\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"http.status_code\", \"operator\": \"exact\", \"type\": \"log_attribute\", \"value\": \"500\" }],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Combine severity and attribute filters\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\"],\n \"filterGroup\": [\n { \"key\": \"k8s.container.name\", \"operator\": \"exact\", \"type\": \"log_resource_attribute\", \"value\": \"web\" }\n ],\n \"dateRange\": { \"date_from\": \"-12h\" }\n }\n}\n```\n\n## Filter by log body content using property filter\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"message\", \"operator\": \"icontains\", \"type\": \"log\", \"value\": \"timeout\" }]\n }\n}\n```\n\n## Check if an attribute exists\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"trace_id\", \"operator\": \"is_set\", \"type\": \"log_attribute\" }]\n }\n}\n```\n\n# Reminders\n\n- Always set `serviceNames` or a resource attribute filter. Never run a broad unfiltered log query.\n- Limit `dateRange` to at most `-1d` (24 hours) unless the user explicitly requests a longer range.\n- When using `logs-attributes-list` or `logs-attribute-values-list`, remember they default to `attribute_type: \"log\"`. Pass `attribute_type: \"resource\"` to search resource-level attributes.\n- Ensure that any property filters are directly relevant to the user's question. Avoid unnecessary filtering.\n- Use `logs-attributes-list` and `logs-attribute-values-list` to discover attributes before guessing filter keys/values.\n- Prefer `searchTerm` for simple text matching; use `filterGroup` with type `log` and key `message` for regex or exact matching.","category": "Logs","feature": "logs","summary": "Query logs",diff --git a/services/mcp/schema/tool-definitions-all.json b/services/mcp/schema/tool-definitions-all.jsonindex 5f5154e41c0f..47bcabf0c03c 100644--- a/services/mcp/schema/tool-definitions-all.json+++ b/services/mcp/schema/tool-definitions-all.json@@ -4822,7 +4822,7 @@"system_prompt_hint": "LLM/AI trace listing and inspection"},"query-logs": {- "description": "Query log entries with filtering by severity, service name, date range, search term, and structured attribute filters. Supports cursor-based pagination. The response schema (see the tool's typed output) lists every returned field — prefer `severity_text` over `severity_number` / `level`, and be aware that `trace_id` and `span_id` return zero-padded strings rather than null when unset.\n\nUse `logs-attributes-list` and `logs-attribute-values-list` to discover available attributes before building filters.\n\n# Workflow — follow this order every time\n\n1. **Discover services first.** Call `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to see available services.\n2. **Explore resource attributes.** Call `logs-attributes-list` with `attribute_type: \"resource\"` to discover resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`). Then call `logs-attribute-values-list` with `attribute_type: \"resource\"` for relevant attributes to validate what data exists.\n3. **Explore log attributes if needed.** Call `logs-attributes-list` (defaults to log attributes) and `logs-attribute-values-list` to discover log-level attributes.\n4. **Size the total volume with `logs-count`.** Call `logs-count` with the discovered `serviceNames` and filters. If it exceeds `query-logs`'s max `limit` of 1000 — or if the user's question is about _when_ something happened — continue to step 5.\n5. **Find where the volume sits with `logs-count-ranges`.** Call `logs-count-ranges` to get time-bucketed counts. Each bucket carries explicit `date_from`/`date_to` you can pass straight back as the next call's `dateRange` to drill into a sub-range. Recurse up to 3–4 levels to narrow onto a spike or a specific window. Stop when the bucket width drops below your precision goal (e.g. 1 minute).\n6. **Only then query logs.** Once the count is in range and the window is right-sized, call `query-logs` with `serviceNames` and any additional filters.\n\nMany cheap calls (attribute/value queries, counts, count-ranges) beat one expensive `query-logs`. Prefer thorough exploration over speculative log searches.\n\nCRITICAL: Be minimalist. Only include filters and settings that are essential to answer the user's specific question. Default settings are usually sufficient unless the user explicitly requests customization.\n\nMANDATORY: Never call query-logs without setting `serviceNames` or at least one `log_resource_attribute` filter. Unfiltered log queries are too broad, expensive, and noisy. If the user hasn't specified a service, use the workflow above to discover services first, then ask or infer.\n\nAll parameters must be nested inside a `query` object.\n\n# Data narrowing\n\n## Property filters\n\nUse property filters via the `query.filterGroup` field to narrow results. Only include property filters when they are essential to directly answer the user's question.\n\nWhen using a property filter, you should:\n\n- **Choose the right type.** Log property types are:\n - `log` — filters the log body/message. Use key \"message\" for this type.\n - `log_attribute` — filters log-level attributes (e.g. \"k8s.container.name\", \"http.method\").\n - `log_resource_attribute` — filters resource-level attributes (e.g. k8s labels, deployment info).\n- **Use `logs-attributes-list` to discover available attribute keys** before building filters.\n- **Use `logs-attribute-values-list` to discover valid values** for a specific attribute key.\n- **Find the suitable operator for the value type** (see supported operators below).\n\n**Important:** The `logs-attributes-list` and `logs-attribute-values-list` tools default to `attribute_type: \"log\"` (log-level attributes). To search resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`), you must explicitly pass `attribute_type: \"resource\"`. Forgetting this will return log-level attributes when you intended resource-level ones.\n\nSupported operators:\n\n- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`\n- Numeric: `exact`, `gt`, `lt`\n- Date: `is_date_exact`, `is_date_before`, `is_date_after`\n- Existence (no value needed): `is_set`, `is_not_set`\n\nThe `value` field accepts a string, number, or array of strings depending on the operator. Omit `value` for `is_set`/`is_not_set`.\n\n## Time period\n\nUse the `query.dateRange` field to control the time window. If the question doesn't mention time, the default is the last hour (`-1h`). Examples of relative dates: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.severityLevels\n\nFilter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels.\n\n## query.serviceNames\n\nFilter by service names. Use `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to discover available services.\n\n## query.searchTerm\n\nFull-text search across log bodies. Use this when the user is looking for specific text in log messages.\n\n## query.orderBy\n\nSort by timestamp: `latest` (default) or `earliest`.\n\n## query.filterGroup\n\nA list of property filters to narrow results. Each filter specifies `key`, `operator`, `type` (log/log_attribute/log_resource_attribute), and optionally `value`. See the \"Property filters\" section above.\n\n## query.dateRange\n\nDate range to filter results. Defaults to the last hour (`-1h`).\n\n- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.limit\n\nMaximum number of results (1-1000). Defaults to 100.\n\n## query.after\n\nCursor for pagination. Use the `nextCursor` value from the previous response.\n\n# Examples\n\n## List recent error logs\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\", \"fatal\"],\n \"serviceNames\": [\"<service>\"]\n }\n}\n```\n\n## Search for a specific log message\n\n```json\n{\n \"query\": {\n \"searchTerm\": \"connection refused\",\n \"serviceNames\": [\"<service>\"],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Filter logs from a specific service\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Filter by a log attribute\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"http.status_code\", \"operator\": \"exact\", \"type\": \"log_attribute\", \"value\": \"500\" }],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Combine severity and attribute filters\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\"],\n \"filterGroup\": [\n { \"key\": \"k8s.container.name\", \"operator\": \"exact\", \"type\": \"log_resource_attribute\", \"value\": \"web\" }\n ],\n \"dateRange\": { \"date_from\": \"-12h\" }\n }\n}\n```\n\n## Filter by log body content using property filter\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"message\", \"operator\": \"icontains\", \"type\": \"log\", \"value\": \"timeout\" }]\n }\n}\n```\n\n## Check if an attribute exists\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"trace_id\", \"operator\": \"is_set\", \"type\": \"log_attribute\" }]\n }\n}\n```\n\n# Reminders\n\n- Always set `serviceNames` or a resource attribute filter. Never run a broad unfiltered log query.\n- Limit `dateRange` to at most `-1d` (24 hours) unless the user explicitly requests a longer range.\n- When using `logs-attributes-list` or `logs-attribute-values-list`, remember they default to `attribute_type: \"log\"`. Pass `attribute_type: \"resource\"` to search resource-level attributes.\n- Ensure that any property filters are directly relevant to the user's question. Avoid unnecessary filtering.\n- Use `logs-attributes-list` and `logs-attribute-values-list` to discover attributes before guessing filter keys/values.\n- Prefer `searchTerm` for simple text matching; use `filterGroup` with type `log` and key `message` for regex or exact matching.",+ "description": "Query log entries with filtering by severity, service name, date range, search term, and structured attribute filters. Supports cursor-based pagination. The response schema (see the tool's typed output) lists every returned field — prefer `severity_text` over `severity_number` / `level`, and be aware that `trace_id` and `span_id` return zero-padded strings rather than null when unset.\n\nUse `logs-attributes-list` and `logs-attribute-values-list` to discover available attributes before building filters.\n\n# Workflow — follow this order every time\n\n1. **Discover services first.** Call `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to see available services.\n2. **Explore resource attributes.** Call `logs-attributes-list` with `attribute_type: \"resource\"` to discover resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`). Then call `logs-attribute-values-list` with `attribute_type: \"resource\"` for relevant attributes to validate what data exists.\n3. **Explore log attributes if needed.** Call `logs-attributes-list` (defaults to log attributes) and `logs-attribute-values-list` to discover log-level attributes.\n4. **Size the total volume with `logs-count`.** Call `logs-count` with the discovered `serviceNames` and filters. If it exceeds `query-logs`'s max `limit` of 1000 — or if the user's question is about _when_ something happened — continue to step 5.\n5. **Find where the volume sits with `logs-count-ranges`.** Call `logs-count-ranges` to get time-bucketed counts. Each bucket carries explicit `date_from`/`date_to` you can pass straight back as the next call's `dateRange` to drill into a sub-range. Recurse up to 3–4 levels to narrow onto a spike or a specific window. Stop when the bucket width drops below your precision goal (e.g. 1 minute).\n6. **Only then query logs.** Once the count is in range and the window is right-sized, call `query-logs` with `serviceNames` and any additional filters.\n\nMany cheap calls (attribute/value queries, counts, count-ranges) beat one expensive `query-logs`. Prefer thorough exploration over speculative log searches.\n\nCRITICAL: Be minimalist. Only include filters and settings that are essential to answer the user's specific question. Default settings are usually sufficient unless the user explicitly requests customization.\n\nMANDATORY: Never call query-logs without setting `serviceNames` or at least one `log_resource_attribute` filter. Unfiltered log queries are too broad, expensive, and noisy. If the user hasn't specified a service, use the workflow above to discover services first, then ask or infer.\n\nAll parameters must be nested inside a `query` object.\n\n# Data narrowing\n\n## Property filters\n\nUse property filters via the `query.filterGroup` field to narrow results. Only include property filters when they are essential to directly answer the user's question.\n\nWhen using a property filter, you should:\n\n- **Choose the right type.** Log property types are:\n - `log` — filters the log body/message. Use key \"message\" for this type.\n - `log_attribute` — filters log-level attributes (e.g. \"k8s.container.name\", \"http.method\").\n - `log_resource_attribute` — filters resource-level attributes (e.g. k8s labels, deployment info).\n- **Use `logs-attributes-list` to discover available attribute keys** before building filters.\n- **Use `logs-attribute-values-list` to discover valid values** for a specific attribute key.\n- **Find the suitable operator for the value type** (see supported operators below).\n\n**Important:** The `logs-attributes-list` and `logs-attribute-values-list` tools default to `attribute_type: \"log\"` (log-level attributes). To search resource-level attributes (e.g. `k8s.pod.name`, `k8s.namespace.name`), you must explicitly pass `attribute_type: \"resource\"`. Forgetting this will return log-level attributes when you intended resource-level ones.\n\nSupported operators:\n\n- String: `exact`, `is_not`, `icontains`, `not_icontains`, `regex`, `not_regex`\n- Numeric: `exact`, `gt`, `lt`\n- Date: `is_date_exact`, `is_date_before`, `is_date_after`\n- Existence (no value needed): `is_set`, `is_not_set`\n\nThe `value` field accepts a string, number, or array of strings depending on the operator. Omit `value` for `is_set`/`is_not_set`.\n\n## Filtering logs by a PostHog person\n\nWhen the user references a person — by `distinct_id`, name, email, or via a prior `persons-retrieve` call — filter logs to that person via a `log_attribute` filter. The attribute key is configurable per project (it defaults to `distinct_id`); read `logs_distinct_id_attribute_key` from the team config (returned on `projects-retrieve` / `environments-retrieve`, or via the `/api/projects/:id/logs_config/` endpoint) and use that as the filter `key`.\n\nIf the team has not configured a custom key, use `distinct_id`. If a person has multiple `distinct_ids`, pass the array as the filter `value` with operator `exact` (matches any of them).\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [\n {\n \"key\": \"distinct_id\",\n \"operator\": \"exact\",\n \"type\": \"log_attribute\",\n \"value\": [\"<distinct_id_1>\", \"<distinct_id_2>\"]\n }\n ]\n }\n}\n```\n\nDo not invent a different attribute key based on what looks plausible — use the configured key. If the configured key returns zero results, the customer's logs pipeline may not stamp person identity at all; tell the user rather than guessing.\n\n## Time period\n\nUse the `query.dateRange` field to control the time window. If the question doesn't mention time, the default is the last hour (`-1h`). Examples of relative dates: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n\n# Parameters\n\nAll parameters go inside `query`.\n\n## query.severityLevels\n\nFilter by log severity: `trace`, `debug`, `info`, `warn`, `error`, `fatal`. Omit to include all levels.\n\n## query.serviceNames\n\nFilter by service names. Use `logs-attribute-values-list` with `key: \"service.name\"` and `attribute_type: \"resource\"` to discover available services.\n\n## query.searchTerm\n\nFull-text search across log bodies. Use this when the user is looking for specific text in log messages.\n\n## query.orderBy\n\nSort by timestamp: `latest` (default) or `earliest`.\n\n## query.filterGroup\n\nA list of property filters to narrow results. Each filter specifies `key`, `operator`, `type` (log/log_attribute/log_resource_attribute), and optionally `value`. See the \"Property filters\" section above.\n\n## query.dateRange\n\nDate range to filter results. Defaults to the last hour (`-1h`).\n\n- `date_from`: Start of the range. Accepts ISO 8601 timestamps or relative formats: `-1h`, `-6h`, `-1d`, `-7d`, `-30d`.\n- `date_to`: End of the range. Same format. Omit or null for \"now\".\n\n## query.limit\n\nMaximum number of results (1-1000). Defaults to 100.\n\n## query.after\n\nCursor for pagination. Use the `nextCursor` value from the previous response.\n\n# Examples\n\n## List recent error logs\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\", \"fatal\"],\n \"serviceNames\": [\"<service>\"]\n }\n}\n```\n\n## Search for a specific log message\n\n```json\n{\n \"query\": {\n \"searchTerm\": \"connection refused\",\n \"serviceNames\": [\"<service>\"],\n \"dateRange\": { \"date_from\": \"-6h\" }\n }\n}\n```\n\n## Filter logs from a specific service\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"api-gateway\"],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Filter by a log attribute\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"http.status_code\", \"operator\": \"exact\", \"type\": \"log_attribute\", \"value\": \"500\" }],\n \"dateRange\": { \"date_from\": \"-1d\" }\n }\n}\n```\n\n## Combine severity and attribute filters\n\n```json\n{\n \"query\": {\n \"severityLevels\": [\"error\"],\n \"filterGroup\": [\n { \"key\": \"k8s.container.name\", \"operator\": \"exact\", \"type\": \"log_resource_attribute\", \"value\": \"web\" }\n ],\n \"dateRange\": { \"date_from\": \"-12h\" }\n }\n}\n```\n\n## Filter by log body content using property filter\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"message\", \"operator\": \"icontains\", \"type\": \"log\", \"value\": \"timeout\" }]\n }\n}\n```\n\n## Check if an attribute exists\n\n```json\n{\n \"query\": {\n \"serviceNames\": [\"<service>\"],\n \"filterGroup\": [{ \"key\": \"trace_id\", \"operator\": \"is_set\", \"type\": \"log_attribute\" }]\n }\n}\n```\n\n# Reminders\n\n- Always set `serviceNames` or a resource attribute filter. Never run a broad unfiltered log query.\n- Limit `dateRange` to at most `-1d` (24 hours) unless the user explicitly requests a longer range.\n- When using `logs-attributes-list` or `logs-attribute-values-list`, remember they default to `attribute_type: \"log\"`. Pass `attribute_type: \"resource\"` to search resource-level attributes.\n- Ensure that any property filters are directly relevant to the user's question. Avoid unnecessary filtering.\n- Use `logs-attributes-list` and `logs-attribute-values-list` to discover attributes before guessing filter keys/values.\n- Prefer `searchTerm` for simple text matching; use `filterGroup` with type `log` and key `message` for regex or exact matching.","category": "Logs","feature": "logs","summary": "Query logs",