ymgyt / tracing-cloudwatch

AWS Cloudwatch layer for tracing-subscriber
MIT License
18 stars 7 forks source link

logs are not sent to cloud watch #37

Closed omofolarin closed 6 months ago

omofolarin commented 6 months ago

I'm trying to use tracing-cloudwatch from an actix actor. The logs is not sent to cloudwatch. To be sure my credentials were working I added the code to create log group/log stream. But the log group and log stream were created from the API as below

fn handle(&mut self, msg: DeploymentMessage, _ctx: &mut Self::Context) -> Self::Result {
        let process = async move {
            let formatting_layer = BunyanFormattingLayer::new("deployment".into(), std::io::stdout);
            let env_filter =
                EnvFilter::try_from_default_env().unwrap_or_else(|_| EnvFilter::new("debug,warning,error,info,tracing"));

            let config = aws_config::from_env().region("us-west-2").load().await;

            dbg!(&config);

            let cw_client = aws_sdk_cloudwatchlogs::Client::new(&config);
            cw_client.create_log_group()
                .set_log_group_name(Some("javline".to_string()))
                .set_log_group_class(Some(LogGroupClass::Standard))
                .set_tags(
                    Some(HashMap::from([("Business".to_string(), "".to_string())]))
                )
                .send()
                .await
                .expect("expect log-group to be created");

            cw_client.create_log_stream()
                .set_log_group_name(Some("javline".to_string()))
                .set_log_stream_name(Some("throw".to_string()))
                .send()
                .await
                .expect("expect log-name to be created");
            let cloudwatch_layer = tracing_cloudwatch::layer().with_client(
                cw_client,
                tracing_cloudwatch::ExportConfig::default()
                    .with_batch_size(5)
                    .with_interval(Duration::from_secs(1))
                    .with_log_group_name("javline")
                    .with_log_stream_name("throw"),
            );

            let subscriber = Registry::default()
                // .with(env_filter)
                // .with(JsonStorageLayer)
                // .with(formatting_layer)
                .with(cloudwatch_layer);

            tracing::subscriber::with_default(subscriber, || async {
                tracing::info!("running deployment build");
                tracing::info!("running deployment build 2");
             }).await

               Ok(msg.0.clone())
        }

            .into_actor(self)
            .map(|result: Result<Deployment, std::io::Error>, _actor, _ctx| {
                match result {
                    Ok(_v) => {
                        Ok(())
                    }
                    // Failed to send message to other_actor
                    Err(e) => Err(std::io::Error::new(ErrorKind::Other, e.to_string())),
                }
            });
omofolarin commented 6 months ago

I tried the with_default without an async closure and It sends the logs to cloudwatch. Please what's the right way to configure tracing-cloudwatch for with-default for async