diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/xyz/driver/core/trace/ExceptionLoggingSizedBufferingTraceConsumer.scala | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/main/scala/xyz/driver/core/trace/ExceptionLoggingSizedBufferingTraceConsumer.scala b/src/main/scala/xyz/driver/core/trace/ExceptionLoggingSizedBufferingTraceConsumer.scala index 64ae15a..399e2c6 100644 --- a/src/main/scala/xyz/driver/core/trace/ExceptionLoggingSizedBufferingTraceConsumer.scala +++ b/src/main/scala/xyz/driver/core/trace/ExceptionLoggingSizedBufferingTraceConsumer.scala @@ -1,9 +1,10 @@ package xyz.driver.core.trace -import com.google.cloud.trace.v1.consumer.{FlushableTraceConsumer} +import com.google.cloud.trace.v1.consumer.FlushableTraceConsumer import com.google.devtools.cloudtrace.v1.Traces import com.typesafe.scalalogging.Logger -import scala.util.Try + +import scala.util.control.NonFatal /** * ExceptionLoggingFlushableTraceConsumer simply wraps a flushable trace consumer and catches/logs any exceptions @@ -19,8 +20,16 @@ class ExceptionLoggingFlushableTraceConsumer(traceConsumer: FlushableTraceConsum log.error(s"Encountered exception logging to google $exception") override def receive(trace: Traces): Unit = - Try(flushableTraceConsumer.receive(trace)).fold(exceptionLogger, identity) + try { + flushableTraceConsumer.receive(trace) + } catch { + case NonFatal(e) => exceptionLogger(e) + } override def flush(): Unit = - Try(flushableTraceConsumer.flush()).fold(exceptionLogger, identity) + try { + flushableTraceConsumer.flush() + } catch { + case NonFatal(e) => exceptionLogger(e) + } } |