From 9b47bf0a60c48ba1a853495b7156a7c069a6a0e1 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Mon, 27 Oct 2025 09:53:58 +0100 Subject: [PATCH 1/3] feat: specify canister log filter --- docs/references/_attachments/ic.did | 4 ++++ docs/references/ic-interface-spec.md | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/references/_attachments/ic.did b/docs/references/_attachments/ic.did index 1380722a20..ca5950d615 100644 --- a/docs/references/_attachments/ic.did +++ b/docs/references/_attachments/ic.did @@ -479,6 +479,10 @@ type delete_canister_snapshot_args = record { type fetch_canister_logs_args = record { canister_id : canister_id; + filter : opt variant { + by_idx : record { start : nat64; end : nat64 }; + by_timestamp_nanos : record { start : nat64; end : nat64 }; + } }; type canister_log_record = record { diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 462964dbf9..9d3746ab74 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -3216,6 +3216,10 @@ A single log is a record with the following fields: - `timestamp_nanos` (`nat64`): the timestamp as nanoseconds since 1970-01-01 at which the log was recorded; - `content` (`blob`): the actual content of the log; +To filter canister logs, an optional filter can be provided and have one of the following variants: +- `by_idx` (`record { start : nat64; end : nat64 }`): only logs are returned whose `idx` is within the provided range (`start` and `end` are inclusive); +- `by_timestamp_nanos` (`record { start : nat64; end : nat64 }`): only logs are returned whose `timestamp_nanos` is within the provided range (`start` and `end` are inclusive). + :::warning The response of a query comes from a single replica, and is therefore not appropriate for security-sensitive applications. @@ -7533,13 +7537,20 @@ A.canister_id ∈ verify_envelope(E, Q.sender, S.system_time) or (S[A.canister_id].canister_log_visibility = AllowedViewers Principals and (Q.sender in S[A.canister_id].controllers or Q.sender in Principals)) +if A.filter = by_idx Range: + Canister_logs = { Log | Log ∈ S.canister_logs[A.canister_id] ∧ Range.start <= Log.idx ∧ Log.idx <= Range.end } +else if A.filter = by_timestamp_nanos Range: + Canister_logs = { Log | Log ∈ S.canister_logs[A.canister_id] ∧ Range.start <= Log.timestamp_nanos ∧ Log.timestamp_nanos <= Range.end } +else: + Canister_logs = S.canister_logs[A.canister_id] + ``` Query response `R`: ```html -{status: "replied"; reply: {arg: candid(S.canister_logs[A.canister_id])}, signatures: Sigs} +{status: "replied"; reply: {arg: candid(Canister_logs)}, signatures: Sigs} ``` From a7f8400f259f57da182e10b56a8c000c83123cd0 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Mon, 9 Mar 2026 12:42:01 +0100 Subject: [PATCH 2/3] fix: end range is exclusive when filtering canister logs --- docs/references/ic-interface-spec.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index fdb307dc8d..665ff66af4 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -3235,8 +3235,8 @@ A single log is a record with the following fields: - `content` (`blob`): the actual content of the log; To filter canister logs, an optional filter can be provided and have one of the following variants: -- `by_idx` (`record { start : nat64; end : nat64 }`): only logs are returned whose `idx` is within the provided range (`start` and `end` are inclusive); -- `by_timestamp_nanos` (`record { start : nat64; end : nat64 }`): only logs are returned whose `timestamp_nanos` is within the provided range (`start` and `end` are inclusive). +- `by_idx` (`record { start : nat64; end : nat64 }`): only logs are returned whose `idx` is within the provided range (`start` is inclusive, but `end` are exclusive); +- `by_timestamp_nanos` (`record { start : nat64; end : nat64 }`): only logs are returned whose `timestamp_nanos` is within the provided range (`start` is inclusive, but `end` are exclusive). :::warning @@ -7706,9 +7706,9 @@ A.canister_id ∈ verify_envelope(E, Q.sender, S.system_time) (S[A.canister_id].canister_log_visibility = AllowedViewers Principals and (Q.sender in S[A.canister_id].controllers or Q.sender in Principals)) if A.filter = by_idx Range: - Canister_logs = { Log | Log ∈ S.canister_logs[A.canister_id] ∧ Range.start <= Log.idx ∧ Log.idx <= Range.end } + Canister_logs = { Log | Log ∈ S.canister_logs[A.canister_id] ∧ Range.start <= Log.idx ∧ Log.idx < Range.end } else if A.filter = by_timestamp_nanos Range: - Canister_logs = { Log | Log ∈ S.canister_logs[A.canister_id] ∧ Range.start <= Log.timestamp_nanos ∧ Log.timestamp_nanos <= Range.end } + Canister_logs = { Log | Log ∈ S.canister_logs[A.canister_id] ∧ Range.start <= Log.timestamp_nanos ∧ Log.timestamp_nanos < Range.end } else: Canister_logs = S.canister_logs[A.canister_id] From 4ff9615dbf757daeb3d54072cd4ac1008c8b3376 Mon Sep 17 00:00:00 2001 From: Martin Raszyk Date: Mon, 9 Mar 2026 12:42:38 +0100 Subject: [PATCH 3/3] typo --- docs/references/ic-interface-spec.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/references/ic-interface-spec.md b/docs/references/ic-interface-spec.md index 665ff66af4..6abd3d09a0 100644 --- a/docs/references/ic-interface-spec.md +++ b/docs/references/ic-interface-spec.md @@ -3235,8 +3235,8 @@ A single log is a record with the following fields: - `content` (`blob`): the actual content of the log; To filter canister logs, an optional filter can be provided and have one of the following variants: -- `by_idx` (`record { start : nat64; end : nat64 }`): only logs are returned whose `idx` is within the provided range (`start` is inclusive, but `end` are exclusive); -- `by_timestamp_nanos` (`record { start : nat64; end : nat64 }`): only logs are returned whose `timestamp_nanos` is within the provided range (`start` is inclusive, but `end` are exclusive). +- `by_idx` (`record { start : nat64; end : nat64 }`): only logs are returned whose `idx` is within the provided range (`start` is inclusive, but `end` is exclusive); +- `by_timestamp_nanos` (`record { start : nat64; end : nat64 }`): only logs are returned whose `timestamp_nanos` is within the provided range (`start` is inclusive, but `end` is exclusive). :::warning