Logs

For instructions on how to authenticate to use this endpoint, see API overview.

Endpoints

GET
POST
GET
POST
GET
PATCH
DELETE
POST
POST
POST
GET
POST
GET
PATCH
DELETE
POST
POST
GET

Retrieve logs has logs

Required API key scopes

logs:read

Example request

GET /api/projects/:project_id/logs/has_logs
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/has_logs/

Example response

Status 200

Create logs impact

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/logs/impact
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/impact/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"total": 0,
"logsWithSessionId": 0,
"sessions": 0,
"logsWithDistinctId": 0,
"users": 0,
"topSessions": [
{
"value": "string",
"count": 0
}
],
"topUsers": [
{
"value": "string",
"count": 0
}
],
"sessionGroupKey": {
"source": "log",
"key": "string"
},
"personGroupKey": {
"source": "log",
"key": "string"
}
}

List all logs metric rules

Required API key scopes

logs:read

Query parameters

  • limit
    integer
  • offset
    integer

Response


Example request

GET /api/projects/:project_id/logs/metric_rules
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/metric_rules/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"metric_name": "string",
"enabled": false,
"filter_group": null,
"value_attribute": "string",
"group_by": [
"string"
],
"source": "logs",
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

Create logs metric rules

Required API key scopes

logs:writemetrics:write

Request parameters

  • name
    string
  • metric_name
    string
  • enabled
    boolean
    Default: false
  • filter_group
  • value_attribute
    string | null
  • group_by
    array
  • source
    Default: logs

Response


Example request

POST /api/projects/:project_id/logs/metric_rules
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/metric_rules/\
-d name="string",\
-d metric_name="string"

Example response

Status 201
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"metric_name": "string",
"enabled": false,
"filter_group": null,
"value_attribute": "string",
"group_by": [
"string"
],
"source": "logs",
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Retrieve logs metric rules

Required API key scopes

logs:read

Path parameters

  • id
    string

Response


Example request

GET /api/projects/:project_id/logs/metric_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/metric_rules/:id/

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"metric_name": "string",
"enabled": false,
"filter_group": null,
"value_attribute": "string",
"group_by": [
"string"
],
"source": "logs",
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Update logs metric rules

Required API key scopes

logs:writemetrics:write

Path parameters

  • id
    string

Request parameters

  • name
    string
  • metric_name
    string
  • enabled
    boolean
    Default: false
  • filter_group
  • value_attribute
    string | null
  • group_by
    array
  • source
    Default: logs

Response


Example request

PATCH /api/projects/:project_id/logs/metric_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/metric_rules/:id/\
-d name="string"

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"metric_name": "string",
"enabled": false,
"filter_group": null,
"value_attribute": "string",
"group_by": [
"string"
],
"source": "logs",
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Delete logs metric rules

Required API key scopes

logs:writemetrics:write

Path parameters

  • id
    string

Example request

DELETE /api/projects/:project_id/logs/metric_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X DELETE \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/metric_rules/:id/

Example response

Status 204 No response body

Create logs patterns

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/logs/patterns
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/patterns/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"source": "stored_patterns",
"pattern_version": 0,
"fallback_reason": "flag_disabled",
"pattern_coverage_pct": 0,
"represented_count": 0,
"remainder_count": 0,
"patterns": [
{
"pattern": "string",
"count": 0,
"estimated_count": 0,
"volume_share_pct": 0.1,
"error_count": 0,
"estimated_error_count": 0,
"first_seen": "string",
"last_seen": "string",
"examples": [
{
"body": "string",
"severity_text": "string",
"service_name": "string",
"timestamp": "string"
}
],
"services": [
"string"
],
"sparkline": [
0
],
"severity_counts": {
"property1": 0,
"property2": 0
},
"match_regex": "string",
"match_literal": "string",
"match_patterns": [
"string"
],
"pattern_version": 0
}
],
"scanned_count": 0,
"total_count": 0,
"sampled": true,
"sample_coverage_pct": 0.1,
"sparkline_buckets": [
{
"start": "string",
"end": "string"
}
]
}

Create logs patterns diff

Required API key scopes

logs:read

Request parameters

  • query
  • baselineDateRange

Response


Example request

POST /api/projects/:project_id/logs/patterns_diff
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/patterns_diff/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"entries": [
{
"classification": "new",
"rate_ratio": 0,
"pattern": {
"pattern": "string",
"count": 0,
"estimated_count": 0,
"volume_share_pct": 0.1,
"error_count": 0,
"estimated_error_count": 0,
"first_seen": "string",
"last_seen": "string",
"examples": [
{
"body": "string",
"severity_text": "string",
"service_name": "string",
"timestamp": "string"
}
],
"services": [
"string"
],
"sparkline": [
0
],
"severity_counts": {
"property1": 0,
"property2": 0
},
"match_regex": "string",
"match_literal": "string",
"match_patterns": [
"string"
],
"pattern_version": 0
},
"baseline_estimated_count": 0,
"baseline_volume_share_pct": 0
}
],
"current": {
"source": "stored_patterns",
"pattern_version": 0,
"fallback_reason": "flag_disabled",
"pattern_coverage_pct": 0,
"represented_count": 0,
"remainder_count": 0,
"scanned_count": 0,
"total_count": 0,
"sampled": true,
"sample_coverage_pct": 0.1,
"date_from": "string",
"date_to": "string"
},
"baseline": {
"source": "stored_patterns",
"pattern_version": 0,
"fallback_reason": "flag_disabled",
"pattern_coverage_pct": 0,
"represented_count": 0,
"remainder_count": 0,
"scanned_count": 0,
"total_count": 0,
"sampled": true,
"sample_coverage_pct": 0.1,
"date_from": "string",
"date_to": "string"
}
}

Create logs query

Required API key scopes

logs:read

Request parameters

  • query

Response


Example request

POST /api/projects/:project_id/logs/query
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/query/\
-d query=undefined

Example response

Status 200
RESPONSE
{
"query": {},
"results": [
{
"uuid": "string",
"timestamp": "string",
"observed_timestamp": "string",
"body": "string",
"severity_text": "string",
"severity_number": 0,
"level": "string",
"trace_id": "string",
"span_id": "string",
"trace_flags": 0,
"attributes": {
"property1": "string",
"property2": "string"
},
"resource_attributes": {
"property1": "string",
"property2": "string"
},
"event_name": "string"
}
],
"hasMore": true,
"nextCursor": "string",
"maxExportableLogs": 0,
"columns": [
"string"
]
}

List all logs retention rules

Retention rules for one record kind.

TracingRetentionRuleViewSet reuses this for span rules, which live in their own model. It swaps the queryset, the serializer and team_rules, so every read and write here goes through team_rules rather than naming a model.

Required API key scopes

logs:read

Query parameters

  • limit
    integer
  • offset
    integer

Response


Example request

GET /api/projects/:project_id/logs/retention_rules
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

Create logs retention rules

Retention rules for one record kind.

TracingRetentionRuleViewSet reuses this for span rules, which live in their own model. It swaps the queryset, the serializer and team_rules, so every read and write here goes through team_rules rather than naming a model.

Required API key scopes

logs:write

Request parameters

  • name
    string
  • enabled
    boolean
    Default: false
  • priority
    integer | null
  • config

Response


Example request

POST /api/projects/:project_id/logs/retention_rules
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/\
-d name="string",\
-d config=undefined

Example response

Status 201
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Retrieve logs retention rules

Retention rules for one record kind.

TracingRetentionRuleViewSet reuses this for span rules, which live in their own model. It swaps the queryset, the serializer and team_rules, so every read and write here goes through team_rules rather than naming a model.

Required API key scopes

logs:read

Path parameters

  • id
    string

Response


Example request

GET /api/projects/:project_id/logs/retention_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/:id/

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Update logs retention rules

Retention rules for one record kind.

TracingRetentionRuleViewSet reuses this for span rules, which live in their own model. It swaps the queryset, the serializer and team_rules, so every read and write here goes through team_rules rather than naming a model.

Required API key scopes

logs:write

Path parameters

  • id
    string

Request parameters

  • name
    string
  • enabled
    boolean
    Default: false
  • priority
    integer | null
  • config

Response


Example request

PATCH /api/projects/:project_id/logs/retention_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X PATCH \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/:id/\
-d name="string"

Example response

Status 200
RESPONSE
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}

Delete logs retention rules

Retention rules for one record kind.

TracingRetentionRuleViewSet reuses this for span rules, which live in their own model. It swaps the queryset, the serializer and team_rules, so every read and write here goes through team_rules rather than naming a model.

Required API key scopes

logs:write

Path parameters

  • id
    string

Example request

DELETE /api/projects/:project_id/logs/retention_rules/:id
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl -X DELETE \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/:id/

Example response

Status 204 No response body

Create logs retention rules reorder

Atomically reassign priorities so the given ID order maps to ascending priorities (0..n-1).

Query parameters

  • limit
    integer
  • offset
    integer

Request parameters

  • ordered_ids
    array

Response


Example request

POST /api/projects/:project_id/logs/retention_rules/reorder
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/reorder/\
-d ordered_ids="array"

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}

Create logs retention rules suggest name

Suggest a human-readable name for a retention rule from its retention tier and filter group. Used by the create form as an auto-suggest; nothing is persisted. Returns an empty name when a suggestion can't be generated.

Request parameters

  • retention_days
    integer
  • filter_group

Response


Example request

POST /api/projects/:project_id/logs/retention_rules/suggest_name
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl
-H 'Content-Type: application/json'\
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/retention_rules/suggest_name/\
-d retention_days="integer",\
-d filter_group=undefined

Example response

Status 200
RESPONSE
{
"name": "string"
}

List all logs sampling rules

Required API key scopes

logs:read

Query parameters

  • limit
    integer
  • offset
    integer

Response


Example request

GET /api/projects/:project_id/logs/sampling_rules
export POSTHOG_PERSONAL_API_KEY=[your personal api key]
curl \
-H "Authorization: Bearer $POSTHOG_PERSONAL_API_KEY" \
<ph_app_host>/api/projects/:project_id/logs/sampling_rules/

Example response

Status 200
RESPONSE
{
"count": 123,
"next": "http://api.example.org/accounts/?offset=400&limit=100",
"previous": "http://api.example.org/accounts/?offset=200&limit=100",
"results": [
{
"id": "497f6eca-6276-4993-bfeb-53cbbbba6f08",
"name": "string",
"enabled": false,
"priority": 0,
"rule_type": "severity_sampling",
"scope_service": "string",
"scope_path_pattern": "string",
"scope_attribute_filters": [
{}
],
"config": null,
"version": 0,
"created_by": 0,
"created_at": "2019-08-24T14:15:22Z",
"updated_at": "2019-08-24T14:15:22Z"
}
]
}