Skip to content

Commit

Permalink
Remove appsignal-wrap from source
Browse files Browse the repository at this point in the history
Remove the `appsignal-wrap` name from everywhere in the source code,
to simplify changing it lately.
  • Loading branch information
unflxw committed Nov 4, 2024
1 parent 1fbfe8e commit 69794fc
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 30 deletions.
3 changes: 2 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,10 +256,11 @@ impl Cli {
#[cfg(test)]
mod tests {
use super::*;
use crate::package::NAME;

// These arguments are required -- without them, the CLI parser will fail.
fn with_required_args(args: Vec<&str>) -> Vec<&str> {
let first_args: Vec<&str> = vec!["appsignal-wrap", "--api-key", "some-api-key"];
let first_args: Vec<&str> = vec![NAME, "--api-key", "some-api-key"];
let last_args: Vec<&str> = vec!["--", "true"];
first_args
.into_iter()
Expand Down
3 changes: 1 addition & 2 deletions src/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use reqwest::{Client, ClientBuilder};

pub const VERSION: &str = env!("CARGO_PKG_VERSION");
pub const NAME: &str = env!("CARGO_PKG_NAME");
use crate::package::{NAME, VERSION};

pub fn client() -> Client {
ClientBuilder::new()
Expand Down
48 changes: 23 additions & 25 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use serde::Serialize;
use crate::client::client;
use crate::ndjson;
use crate::timestamp::Timestamp;
use crate::package::NAME;

pub struct LogConfig {
pub api_key: String,
Expand Down Expand Up @@ -85,7 +86,7 @@ impl LogMessage {
) -> Self {
let mut attributes = HashMap::new();

attributes.insert("appsignal-wrap-digest".to_string(), config.digest.clone());
attributes.insert(format!("{}-digest", NAME), config.digest.clone());

Self {
group: config.group.clone(),
Expand Down Expand Up @@ -149,30 +150,27 @@ mod tests {
"application/x-ndjson"
);
assert_eq!(
request.body().unwrap().as_bytes(),
Some(
format!(
concat!(
"{{",
r#""group":"some-group","#,
r#""timestamp":"{}","#,
r#""severity":"info","#,
r#""message":"first-message","#,
r#""hostname":"some-hostname","#,
r#""attributes":{{"digest":"some-digest"}}"#,
"}}\n",
"{{",
r#""group":"some-group","#,
r#""timestamp":"{}","#,
r#""severity":"error","#,
r#""message":"second-message","#,
r#""hostname":"some-hostname","#,
r#""attributes":{{"digest":"some-digest"}}"#,
"}}\n"
),
EXPECTED_RFC3339, EXPECTED_RFC3339
)
.as_bytes()
String::from_utf8_lossy(request.body().unwrap().as_bytes().unwrap()),
format!(
concat!(
"{{",
r#""group":"some-group","#,
r#""timestamp":"{}","#,
r#""severity":"info","#,
r#""message":"first-message","#,
r#""hostname":"some-hostname","#,
r#""attributes":{{"{}-digest":"some-digest"}}"#,
"}}\n",
"{{",
r#""group":"some-group","#,
r#""timestamp":"{}","#,
r#""severity":"error","#,
r#""message":"second-message","#,
r#""hostname":"some-hostname","#,
r#""attributes":{{"{}-digest":"some-digest"}}"#,
"}}\n"
),
EXPECTED_RFC3339, NAME, EXPECTED_RFC3339, NAME
)
);
}
Expand Down
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ mod exit;
mod ndjson;
mod signals;
mod timestamp;
mod package;

use crate::check_in::{CronKind, HeartbeatConfig};
use crate::cli::Cli;
use crate::client::client;
use crate::log::{LogConfig, LogMessage, LogSeverity};
use crate::signals::{has_terminating_intent, reset_sigpipe, signal_stream};
use crate::timestamp::SystemTimestamp;
use crate::package::NAME;

use ::log::{debug, error, trace};
use std::os::unix::process::ExitStatusExt;
Expand All @@ -40,7 +42,7 @@ fn main() {
env_logger::Builder::from_env(Env::default().default_filter_or("info"))
.format(|buf, record| {
let level = record.level().to_string().to_ascii_lowercase();
writeln!(buf, "appsignal-wrap: {}: {}", level, record.args())
writeln!(buf, "{}: {}: {}", NAME, level, record.args())
})
.init();

Expand Down Expand Up @@ -330,7 +332,7 @@ async fn start(cli: Cli) -> Result<i32, Box<dyn std::error::Error>> {
// While we wait for the tasks to complete, we need to continue to listen to those
// signal handlers.
//
// This allows for `appsignal-wrap` to be terminated by certain signals both before
// This allows for the wrapper process to be terminated by certain signals both before
// and after the child process' lifetime.
//
// See https://docs.rs/tokio/latest/tokio/signal/unix/struct.Signal.html#caveats
Expand Down
2 changes: 2 additions & 0 deletions src/package.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub const NAME: &str = env!("CARGO_PKG_NAME");
pub const VERSION: &str = env!("CARGO_PKG_VERSION");

0 comments on commit 69794fc

Please sign in to comment.