mononoke/edenapi: don't discard ctx.scuba() logs

Summary:
This has been here for a little while, but it's worth changing. Currently, we
entirely discard logs coming via a CoreContext in EdenAPI.

We don't typically log many of those anywhere in Mononoke, but when we do they
tend to be for error conditions, warnings, or aggregated reporting, and can be
quite meaningful as a result.

So, let's update to not discard them. To make it easy to differentiate those
logs from EdenAPI request-level logs (even though they'll both have `service` =
`edenapi`), let's give the latter a Log Tag (which is consistent with what
we do in repo client).

Differential Revision: D28350733

fbshipit-source-id: 3b12a4b56f28435460186e1f7578163ca7bdaebc
This commit is contained in:
Thomas Orozco 2021-05-11 06:44:43 -07:00 committed by Facebook GitHub Bot
parent 212cd894ca
commit baaf300c12
2 changed files with 16 additions and 4 deletions

View File

@ -42,7 +42,7 @@ pub type EdenApi = MononokeHttpHandler<Router>;
pub fn build(
fb: FacebookInit,
logger: Logger,
scuba: MononokeScubaSampleBuilder,
mut scuba: MononokeScubaSampleBuilder,
mononoke: Mononoke,
will_exit: Arc<AtomicBool>,
test_friendly_loging: bool,
@ -70,11 +70,19 @@ pub fn build(
"edenapi_server",
)))
.add(PostResponseMiddleware::default())
.add(RequestContextMiddleware::new(fb, logger, load_limiter))
.add(RequestContextMiddleware::new(
fb,
logger,
scuba.clone(),
load_limiter,
))
.add(LoadMiddleware::new())
.add(log_middleware)
.add(OdsMiddleware::new())
.add(<ScubaMiddleware<EdenApiScubaHandler>>::new(scuba))
.add(<ScubaMiddleware<EdenApiScubaHandler>>::new({
scuba.add("log_tag", "EdenAPI Request Processed");
scuba
}))
.add(TimerMiddleware::new())
.build(router);

View File

@ -10,6 +10,7 @@ use gotham_derive::StateData;
use hyper::{Body, Response};
use load_limiter::LoadLimiterEnvironment;
use slog::{o, Logger};
use std::sync::Arc;
use context::{CoreContext, SessionContainer};
use fbinit::FacebookInit;
@ -33,6 +34,7 @@ impl RequestContext {
pub struct RequestContextMiddleware {
fb: FacebookInit,
logger: Logger,
scuba: Arc<MononokeScubaSampleBuilder>,
load_limiter: Option<LoadLimiterEnvironment>,
}
@ -40,11 +42,13 @@ impl RequestContextMiddleware {
pub fn new(
fb: FacebookInit,
logger: Logger,
scuba: MononokeScubaSampleBuilder,
load_limiter: Option<LoadLimiterEnvironment>,
) -> Self {
Self {
fb,
logger,
scuba: Arc::new(scuba),
load_limiter,
}
}
@ -67,7 +71,7 @@ impl Middleware for RequestContextMiddleware {
let request_id = request_id(&state);
let logger = self.logger.new(o!("request_id" => request_id.to_string()));
let ctx = session.new_context(logger.clone(), MononokeScubaSampleBuilder::with_discard());
let ctx = session.new_context(logger.clone(), (*self.scuba).clone());
state.put(RequestContext::new(ctx, logger).await);