From 0a94e502b800f98a74b30756c1bed6b36ada9bcf Mon Sep 17 00:00:00 2001 From: Shairyar Baig Date: Wed, 3 Sep 2025 16:44:21 +0500 Subject: [PATCH 1/4] Add helpful message for 401 errors about app-level keys --- ...-to-know-if-wrong-api-key-is-being-used.md | 8 +++++++ src/main.rs | 22 ++++++++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100644 .changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md diff --git a/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md b/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md new file mode 100644 index 0000000..3214679 --- /dev/null +++ b/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md @@ -0,0 +1,8 @@ +--- +bump: patch +type: add +--- + +Show helpful error message for incorrect API key usage. + +When users encounter unauthorized errors, it will be easy for them to know they are using the wrong key. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index b817c58..191b16c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -754,11 +754,23 @@ async fn send_batch( let response = client.post(url.clone()).body(batch_bytes).send().await?; - info!( - "Batch of {} metrics sent: {:?}", - batch.get_metrics().len(), - response.status() - ); + let status = response.status(); + + trace!("HTTP response status: {}", status); + + if status == 401 { + warn!( + "Batch of {} metrics failed to send: {:?} - Make sure you're using an app-level key", + batch.get_metrics().len(), + status + ); + } else { + info!( + "Batch of {} metrics sent: {:?}", + batch.get_metrics().len(), + status + ); + } Ok(response) } From e37c480abcd976bf224cfd45b0ea001e572b3eef Mon Sep 17 00:00:00 2001 From: Shairyar Baig Date: Tue, 9 Sep 2025 15:34:57 +0500 Subject: [PATCH 2/4] Improve HTTP status code handling and error messaging - Use is_success() method for proper HTTP status classification - Display human-readable status codes (e.g., '401 Unauthorized') --- src/main.rs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/main.rs b/src/main.rs index 191b16c..8faf41e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -756,19 +756,26 @@ async fn send_batch( let status = response.status(); - trace!("HTTP response status: {}", status); - - if status == 401 { + if status.is_success() { + info!( + "Batch of {} metrics sent successfully (HTTP response status: {} {})", + batch.get_metrics().len(), + status, + status.canonical_reason().unwrap_or("Unknown") + ); + } else if status == 401 { warn!( - "Batch of {} metrics failed to send: {:?} - Make sure you're using an app-level key", + "Batch of {} metrics failed to send (HTTP response status: {} {}) - make sure you're using an *app-level* push API key", batch.get_metrics().len(), - status + status, + status.canonical_reason().unwrap_or("Unknown") ); } else { - info!( - "Batch of {} metrics sent: {:?}", + warn!( + "Batch of {} metrics failed to send (HTTP response status: {} {})", batch.get_metrics().len(), - status + status, + status.canonical_reason().unwrap_or("Unknown") ); } From ee377235cdc18ca6deadd6be360d1a50f456dd5a Mon Sep 17 00:00:00 2001 From: shairyar Date: Tue, 9 Sep 2025 15:39:57 +0500 Subject: [PATCH 3/4] Clarify changeset description The changeset aims to be descriptive of the functionality. Co-authored-by: Noemi <45180344+unflxw@users.noreply.github.com> --- .../make-it-easy-to-know-if-wrong-api-key-is-being-used.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md b/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md index 3214679..3a1c9b8 100644 --- a/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md +++ b/.changesets/make-it-easy-to-know-if-wrong-api-key-is-being-used.md @@ -3,6 +3,4 @@ bump: patch type: add --- -Show helpful error message for incorrect API key usage. - -When users encounter unauthorized errors, it will be easy for them to know they are using the wrong key. \ No newline at end of file +When a request to AppSignal returns a `401 Unauthorized` error status code, display a log message asking the customer to ensure they're using an app-level push API key. \ No newline at end of file From 6ca74cd4b2adb77ae7483b7f2befc773bdbc3634 Mon Sep 17 00:00:00 2001 From: shairyar Date: Tue, 9 Sep 2025 16:57:10 +0500 Subject: [PATCH 4/4] Remove redundant calls that were causing duplicate text - Simplify log formatting to use status Display trait directly --- src/main.rs | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/src/main.rs b/src/main.rs index 8faf41e..0160eef 100644 --- a/src/main.rs +++ b/src/main.rs @@ -758,24 +758,21 @@ async fn send_batch( if status.is_success() { info!( - "Batch of {} metrics sent successfully (HTTP response status: {} {})", + "Batch of {} metrics sent successfully (HTTP response status: {})", batch.get_metrics().len(), - status, - status.canonical_reason().unwrap_or("Unknown") + status ); } else if status == 401 { warn!( - "Batch of {} metrics failed to send (HTTP response status: {} {}) - make sure you're using an *app-level* push API key", + "Batch of {} metrics failed to send (HTTP response status: {}) - make sure you're using an *app-level* push API key", batch.get_metrics().len(), - status, - status.canonical_reason().unwrap_or("Unknown") + status ); } else { warn!( - "Batch of {} metrics failed to send (HTTP response status: {} {})", + "Batch of {} metrics failed to send (HTTP response status: {})", batch.get_metrics().len(), - status, - status.canonical_reason().unwrap_or("Unknown") + status ); }