diff options
author | John St. John <jstjohn@users.noreply.github.com> | 2017-09-27 11:25:53 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-27 11:25:53 -0700 |
commit | f384bfcf0870c3881a3a4c6afb6eca9baf163077 (patch) | |
tree | 84820824801474f680c79fd0373e373443f67a16 /src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala | |
parent | 26a5eb401c48c08812f1292664848595e7f74806 (diff) | |
parent | 8a66e1a0e62187d850e665af0d17431272775705 (diff) | |
download | driver-core-f384bfcf0870c3881a3a4c6afb6eca9baf163077.tar.gz driver-core-f384bfcf0870c3881a3a4c6afb6eca9baf163077.tar.bz2 driver-core-f384bfcf0870c3881a3a4c6afb6eca9baf163077.zip |
Merge pull request #68 from drivergroup/jstjohn/catch_and_log_google_exceptions_in_tracing
Catch and log google tracing exceptions rather than crashing the app
Diffstat (limited to 'src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala')
-rw-r--r-- | src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala b/src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala index 7fed3c7..cd9170a 100644 --- a/src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala +++ b/src/main/scala/xyz/driver/core/trace/GoogleStackdriverTraceWithConsumer.scala @@ -6,20 +6,25 @@ import com.google.cloud.trace.sink.TraceSink import com.google.cloud.trace.v1.TraceSinkV1 import com.google.cloud.trace.v1.consumer.{SizedBufferingTraceConsumer, TraceConsumer} import com.google.cloud.trace.v1.producer.TraceProducer -import com.google.cloud.trace.v1.util.RoughTraceSizer import com.google.cloud.trace.{SpanContextHandler, SpanContextHandlerTracer, Tracer} +import com.typesafe.scalalogging.Logger import scala.compat.java8.OptionConverters._ final class GoogleStackdriverTraceWithConsumer(projectId: String, appName: String, appEnvironment: String, - traceConsumer: TraceConsumer) + traceConsumer: TraceConsumer, + log: Logger, + bufferSize: Int) extends GoogleServiceTracer { private val traceProducer: TraceProducer = new TraceProducer() - private val threadSafeBufferingTraceConsumer = - new SizedBufferingTraceConsumer(traceConsumer, new RoughTraceSizer(), 100) + // use a UnitTraceSizer so the interpretation of bufferSize is # of spans to hold in memory prior to flushing + private val threadSafeBufferingTraceConsumer = new ExceptionLoggingFlushableTraceConsumer( + new SizedBufferingTraceConsumer(traceConsumer, new UnitTraceSizer(), bufferSize), + log + ) private val traceSink: TraceSink = new TraceSinkV1(projectId, traceProducer, threadSafeBufferingTraceConsumer) @@ -69,7 +74,8 @@ final class GoogleStackdriverTraceWithConsumer(projectId: String, override def endSpan(span: TracerSpanPayload): Unit = { span.tracer.endSpan(span.context) - threadSafeBufferingTraceConsumer.flush() // flush out the thread safe buffer } + override def flush(): Unit = threadSafeBufferingTraceConsumer.flush() // flush out the thread safe buffer + } |