Skip to content

Commit

Permalink
[blob] use json logs with tracing for blob service
Browse files Browse the repository at this point in the history
Summary: Similar to what we do on the identity service, this enables json logs with the blob service

Test Plan: applied to staging and confirmed json logs in cloudwatch

Reviewers: bartek, varun

Reviewed By: bartek

Subscribers: ashoat, tomek

Differential Revision: https://phab.comm.dev/D13393
  • Loading branch information
wyilio committed Sep 20, 2024
1 parent b9bdf51 commit 8ede856
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
2 changes: 1 addition & 1 deletion services/blob/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@ tonic = "0.8"
tracing = { workspace = true }
tracing-actix-web = { workspace = true }
tracing-futures = { workspace = true, features = ["futures-03"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing-subscriber = { workspace = true, features = ["env-filter", "json"] }
serde_json = { workspace = true }
1 change: 1 addition & 0 deletions services/blob/src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ pub mod db {

// Environment variables

pub const COMM_SERVICES_USE_JSON_LOGS: &str = "COMM_SERVICES_USE_JSON_LOGS";
pub const LOG_LEVEL_ENV_VAR: &str =
tracing_subscriber::filter::EnvFilter::DEFAULT_ENV;

Expand Down
20 changes: 18 additions & 2 deletions services/blob/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,34 @@ pub mod tools;
use anyhow::Result;
use comm_lib::auth::AuthService;
use config::Command;
use constants::COMM_SERVICES_USE_JSON_LOGS;
use std::env;
use tracing_subscriber::filter::{EnvFilter, LevelFilter};

use crate::service::BlobServiceConfig;

fn configure_logging() -> Result<()> {
let use_json_logs: bool = env::var(COMM_SERVICES_USE_JSON_LOGS)
.unwrap_or("false".to_string())
.parse()
.unwrap_or_default();

let filter = EnvFilter::builder()
.with_default_directive(LevelFilter::INFO.into())
.with_env_var(constants::LOG_LEVEL_ENV_VAR)
.from_env_lossy();

let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish();
tracing::subscriber::set_global_default(subscriber)?;
if use_json_logs {
let subscriber = tracing_subscriber::fmt()
.json()
.with_env_filter(filter)
.finish();
tracing::subscriber::set_global_default(subscriber)?;
} else {
let subscriber = tracing_subscriber::fmt().with_env_filter(filter).finish();
tracing::subscriber::set_global_default(subscriber)?;
}

Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions services/terraform/remote/service_blob.tf
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ resource "aws_ecs_task_definition" "blob_service" {
{
name = "COMM_SERVICES_DISABLE_CSAT_VERIFICATION",
value = local.is_staging ? "false" : "true"
},
{
name = "COMM_SERVICES_USE_JSON_LOGS",
value = local.comm_services_use_json_logs
}
]
logConfiguration = {
Expand Down

0 comments on commit 8ede856

Please sign in to comment.