-
Notifications
You must be signed in to change notification settings - Fork 648
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve console span exporter #505
Improve console span exporter #505
Conversation
Codecov Report
@@ Coverage Diff @@
## master #505 +/- ##
==========================================
- Coverage 89.33% 88.70% -0.64%
==========================================
Files 43 43
Lines 2176 2266 +90
Branches 248 258 +10
==========================================
+ Hits 1944 2010 +66
- Misses 161 178 +17
- Partials 71 78 +7
Continue to review full report at Codecov.
|
The current version of the exporter prints everything in a single line, making it difficult to read. It's also missing events, links and attributes. This commit changes the console span exporter to use multiple lines and also adds the missing information about attributes, events and links.
b0f139a
to
06d1713
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a suggestion here 👍
One note I'll just call out is that by providing a json representation via the console exporters, users will begin to depend on the json output of the exporter. On json in particular, it may be a better practice to create a JsonSpanExporter, and then use that in the examples (of course then people would ask why have an uglier consolespanexporter). |
What's the risk if people start relying on the output from the console exporter?, I think it'll only change if the internals of the span change, otherwise I think it should be quite stable. Anyway, we could make it clear that the output should not be used and that we don't guarantee any stability there. What I don't want to do is to expend time trying to create our custom representation, I tried and I found that it is very difficult to create a nice and complete one, that's the reason I decided to switch to a standard like json. |
Maybe the JSON-like output of the standard formatter as it is now can be made less JSON looking by some easy to implement change, in order to make it less likely that our users would expect for this output to be reliable JSON. Something like this: from json import dumps
from re import sub
data = {1: 2, 3: {4: 5, 6: {3: 6}}}
print(dumps(data, indent=4))
print(sub("\s*{", "", sub("\s*}", "", dumps(data, indent=4))))
|
util.ns_to_iso_str(self.start_time) if self.start_time else "None", | ||
util.ns_to_iso_str(self.end_time) if self.end_time else "None", | ||
) | ||
def format_context(context): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do these need to be inline functions? why not utility functions outside of the string?
I haven't done the investigation, but I wonder if that's adding overhead by requiring lambdas to be generated dynamically every time str is called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I moved them as static functions on the class.
util.ns_to_iso_str(self.end_time) if self.end_time else "None", | ||
) | ||
def format_context(context): | ||
x_ctx = OrderedDict() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this necessary? also in python3.7 and above, dicts are always ordered.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think so. The main purpose of this exporter is for debugging, so I think guaranteeing that the output order is deterministic will help a lot.
- move helpers methods to be part class instead of inlined functions - use to_json() instead of __str__()
I updated the PR to use |
I closed it by mistake while cleaning up some branches. It's open and waiting for more reviews. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a question re. the http test, otherwise this looks great.
@@ -32,7 +32,7 @@ def test_http(self): | |||
output = subprocess.check_output( | |||
(sys.executable, test_script) | |||
).decode() | |||
self.assertIn('name="/"', output) | |||
self.assertIn('"name":', output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason this is changing the test to not check for /
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for catching that, updated.
Approving this, I think that we can sort out formatting details later, but this is a fantastic step forward on the very hard to read console spans we have now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
The current version of the exporter prints everything in a single line, making it difficult to read. It's also missing events, links and attributes. This commit changes the console span exporter to use multiple lines and also adds the missing information about attributes, events and links.
* chore: add @obecny in CODEOWNERS * chore: update approvers list
The current version of the exporter prints everything in a single line, making
it difficult to read. It's also missing events, links and attributes.
This commit changes the console span exporter to use multiple lines and also
adds the missing information about attributes, events and links.
Fixes: #478
I started thinking it was a super easy task, then I realized it was more complex than I anticipated. I ended up with this version, I would like to know opinions on this.
Edit: I realized It was getting too messy by handling all the indentation logic and so on. I created a new version that uses json to format the spans.
Example code:
Example output: