Skip to content

Commit

Permalink
chore(observability): Prefer using Display for logging errors (#6389)
Browse files Browse the repository at this point in the history
* chore(observability): Prefer using Display for logging errors

The CONTRIBUTING guide accidentally had an example of using Debug, but
we'd decided to prefer Display for errors.

Fixes #6380

Signed-off-by: Jesse Szwedko <jesse@szwedko.me>
  • Loading branch information
jszwedko authored Feb 9, 2021
1 parent 879c5f5 commit b2481db
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 13 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,7 @@ warn!("Failed to merge value: {}.", err);
Yep!

```rust
warn!(message = "Failed to merge value.", error = ?error);
warn!(message = "Failed to merge value.", %error);
```

#### Feature flags
Expand Down
2 changes: 1 addition & 1 deletion lib/file-source/src/file_server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ where
match result {
Ok(()) => {}
Err(error) => {
error!(message = "Output channel closed.", error = ?error);
error!(message = "Output channel closed.", %error);
return Err(error);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/sinks/util/adaptive_concurrency/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ where
} else {
warn!(
message = "Unhandled error response.",
?error,
%error,
internal_log_rate_secs = 5
);
false
Expand Down
16 changes: 6 additions & 10 deletions tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,11 +174,7 @@ impl SourceConfig for MockSourceConfig {
}
})
.map(Ok)
.forward(
out.sink_map_err(
|error| error!(message = "Error sending in sink..", error = ?error),
),
)
.forward(out.sink_map_err(|error| error!(message = "Error sending in sink..", %error)))
.inspect(|_| info!("Finished sending."))
.await
}))
Expand Down Expand Up @@ -290,7 +286,7 @@ impl TransformConfig for MockTransformConfig {
pub struct MockSinkConfig<T>
where
T: Sink<Event> + Unpin + std::fmt::Debug + Clone + Send + Sync + 'static,
<T as Sink<Event>>::Error: std::fmt::Debug,
<T as Sink<Event>>::Error: std::fmt::Display,
{
#[serde(skip)]
sink: Option<T>,
Expand All @@ -301,7 +297,7 @@ where
impl<T> MockSinkConfig<T>
where
T: Sink<Event> + Unpin + std::fmt::Debug + Clone + Send + Sync + 'static,
<T as Sink<Event>>::Error: std::fmt::Debug,
<T as Sink<Event>>::Error: std::fmt::Display,
{
pub fn new(sink: T, healthy: bool) -> Self {
Self {
Expand All @@ -322,7 +318,7 @@ enum HealthcheckError {
impl<T> SinkConfig for MockSinkConfig<T>
where
T: Sink<Event> + Unpin + std::fmt::Debug + Clone + Send + Sync + 'static,
<T as Sink<Event>>::Error: std::fmt::Debug,
<T as Sink<Event>>::Error: std::fmt::Display,
{
async fn build(&self, cx: SinkContext) -> Result<(VectorSink, Healthcheck), vector::Error> {
let sink = MockSink {
Expand Down Expand Up @@ -361,12 +357,12 @@ struct MockSink<S> {
impl<S> StreamSink for MockSink<S>
where
S: Sink<Event> + Send + std::marker::Unpin,
<S as Sink<Event>>::Error: std::fmt::Debug,
<S as Sink<Event>>::Error: std::fmt::Display,
{
async fn run(&mut self, mut input: BoxStream<'_, Event>) -> Result<(), ()> {
while let Some(event) = input.next().await {
if let Err(error) = self.sink.send(event).await {
error!(message = "Ingesting an event failed at mock sink.", ?error);
error!(message = "Ingesting an event failed at mock sink.", %error);
}

self.acker.ack(1);
Expand Down

0 comments on commit b2481db

Please sign in to comment.