From ad65114811cd09ebd79d89df2a43f0ee8d0ac694 Mon Sep 17 00:00:00 2001 From: Gabe Joseph Date: Wed, 29 Apr 2020 18:46:37 -0600 Subject: [PATCH] Default FileExporter file_mode to a The current default, `w+`, overwrites the contents of the file on the first write. Since `emit` opens and writes to the file every time it's called, this effectively rewrites the file on every `emit`. Perhaps this is intended behavior, but it took me a while to understand why there was only one span written to my file, even though I could tell multiple were being emitted. I didn't have my [Python file mode tables](https://docs.python.org/3/library/functions.html#open) memorized, so at first glance `w+` sounded like "write mode, + for append", and I overlooked it while debugging. I think `a` (append) would be a more intuitive default. --- opencensus/trace/file_exporter.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/opencensus/trace/file_exporter.py b/opencensus/trace/file_exporter.py index baaeaddfc..85d51a759 100644 --- a/opencensus/trace/file_exporter.py +++ b/opencensus/trace/file_exporter.py @@ -36,13 +36,13 @@ class FileExporter(base_exporter.Exporter): :type file_mode: str :param file_mode: The file mode to open the output file with. - Defaults to w+ + Defaults to a """ def __init__(self, file_name=DEFAULT_FILENAME, transport=sync.SyncTransport, - file_mode='w+'): + file_mode='a'): self.file_name = file_name self.transport = transport(self) self.file_mode = file_mode