diff --git a/ddtrace/tracer/tracer_test.go b/ddtrace/tracer/tracer_test.go index c5e204ea8b..6be3ab10df 100644 --- a/ddtrace/tracer/tracer_test.go +++ b/ddtrace/tracer/tracer_test.go @@ -60,6 +60,14 @@ loop: } } +// setLogWriter sets the io.Writer that any new logTraceWriter will write to and returns a function +// which will return the io.Writer to its original value. +func setLogWriter(w io.Writer) func() { + tmp := logWriter + logWriter = w + return func() { logWriter = tmp } +} + // TestTracerCleanStop does frenetic testing in a scenario where the tracer is started // and stopped in parallel with spans being created. func TestTracerCleanStop(t *testing.T) { @@ -89,10 +97,12 @@ func TestTracerCleanStop(t *testing.T) { }() } + defer setLogWriter(ioutil.Discard)() wg.Add(1) go func() { defer wg.Done() for i := 0; i < n; i++ { + // Lambda mode is used to avoid the startup cost associated with agent discovery. Start(withTransport(transport), WithLambdaMode(true)) time.Sleep(time.Millisecond) Start(withTransport(transport), WithLambdaMode(true), WithSampler(NewRateSampler(0.99))) diff --git a/ddtrace/tracer/writer.go b/ddtrace/tracer/writer.go index 8062b711c2..8faab1dfc4 100644 --- a/ddtrace/tracer/writer.go +++ b/ddtrace/tracer/writer.go @@ -104,6 +104,9 @@ func (h *agentTraceWriter) flush() { h.payload = newPayload() } +// logWriter specifies the output target of the logTraceWriter; replaced in tests. +var logWriter io.Writer = os.Stdout + // logTraceWriter encodes traces into a format understood by the Datadog Forwarder // (https://github.com/DataDog/datadog-serverless-functions/tree/master/aws/logs_monitoring) // and writes them to os.Stdout. This is used to send traces from an AWS Lambda environment. @@ -117,7 +120,7 @@ type logTraceWriter struct { func newLogTraceWriter(c *config) *logTraceWriter { w := &logTraceWriter{ config: c, - w: os.Stdout, + w: logWriter, } w.resetBuffer() return w