Skip to content
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

stop rendering empty fields, refactor field conversion #83

Merged
merged 5 commits into from
Aug 4, 2021

Conversation

hawkw
Copy link
Member

@hawkw hawkw commented Aug 4, 2021

Depends on #81 (since it touches the same code and would cause merge conflicts).

  • feat(console): don't display fields with "" values

Now that Tokio supports optional user-provided task names
(in tokio-rs/tokio#3881), the task spans it generates may contain empty
fields (if the user does not provide a name for a spawned task).
However, the console always displays the task.name field, even when
they are empty. This wastes space, and looks kind of ugly.

This branch updates the console to skip displaying fields whose value is
the empty string.

Before:

image

After:

image

Signed-off-by: Eliza Weisman eliza@buoyant.io

  • refac(console): factor out field from pb conversion

This factors out the protobuf Field -> internal Field conversion
into a method, and cleans it up a bit. No functional change, except that
we now take the proto Field type by value, so we don't have to clone
strings out of it like we did previously (due to taking it by
reference). I also added the metadata ID to the Metadata type, so that
we can continue asserting that the metadata's ID matches the expected
one for the field, without having to pass that in separately.

Signed-off-by: Eliza Weisman eliza@buoyant.io

hawkw added 4 commits August 4, 2021 09:04
This branch updates the console to truncate fields named
`spawn.location` when formatting fields on task spans, if the field's
value is a path in the Cargo registry.

Paths in the Cargo registry tend to look like this:
```
/home/eliza/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.9.0/src/runtime/basic_scheduler.rs:157:24
```
We perform the truncation using a regular expression matching strings
beginning with a `/` and accepting up to the string
`/.cargo/registry/src`, followed by one additional path
segment for the `github.com-<SHA>` part. The first match found in the
string is replaced with the string `<cargo>`, so that it's clear the
path is in the Cargo registry.

This could, alternatively, have been implemented by parsing the paths to
a `std::path::Path` and actually inspecting path segments. This might be
more *semantically* correct than using a regex. However, the issue here
is that the paths in the `spawn.location` field are generated in the
environment where the instrumented program is _compiled_, rather than in
the environment where the console application is running. This might,
for example, be on an OS with a different path separator, and
`std::path::Path` defaults to using the system's path separator. We
could work around this, theoretically, but the regex seemed much
simpler.

Closes #74
Now that Tokio supports optional user-provided task names
(in tokio-rs/tokio#3881), the task spans it generates may contain empty
fields (if the user does not provide a name for a spawned task).
However, the console always displays the `task.name` field, even when
they are empty. This wastes space, and looks kind of ugly.

This branch updates the console to skip displaying fields whose value is
the empty string.

### Before:
![image](https://user-images.githubusercontent.com/2796466/128227118-7ee3b4d7-634f-410f-a1d0-4e5afd423566.png)

### After:
![image](https://user-images.githubusercontent.com/2796466/128227203-248bd059-839a-4254-8470-2761f726c885.png)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
This factors out the protobuf `Field` -> internal `Field` conversion
into a method, and cleans it up a bit. No functional change, except that
we now take the proto `Field` type by value, so we don't have to clone
strings out of it like we did previously (due to taking it by
reference). I also added the metadata ID to the `Metadata` type, so that
we can continue asserting that the metadata's ID matches the expected
one for the field, without having to pass that in separately.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Base automatically changed from eliza/truncate-paths to main August 4, 2021 17:49
Copy link
Collaborator

@zaharidichev zaharidichev left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@hawkw hawkw merged commit 9621682 into main Aug 4, 2021
@hawkw hawkw deleted the eliza/empty-fields branch August 4, 2021 21:24
hawkw added a commit that referenced this pull request Aug 4, 2021
Depends on #81 (since it touches the same code and would cause merge conflicts).

* feat(console): don't display fields with "" values

Now that Tokio supports optional user-provided task names
(in tokio-rs/tokio#3881), the task spans it generates may contain empty
fields (if the user does not provide a name for a spawned task).
However, the console always displays the `task.name` field, even when
they are empty. This wastes space, and looks kind of ugly.

This branch updates the console to skip displaying fields whose value is
the empty string.

### Before:
![image](https://user-images.githubusercontent.com/2796466/128227118-7ee3b4d7-634f-410f-a1d0-4e5afd423566.png)

### After:
![image](https://user-images.githubusercontent.com/2796466/128227203-248bd059-839a-4254-8470-2761f726c885.png)

Signed-off-by: Eliza Weisman <eliza@buoyant.io>

* refac(console): factor out field from pb conversion

This factors out the protobuf `Field` -> internal `Field` conversion
into a method, and cleans it up a bit. No functional change, except that
we now take the proto `Field` type by value, so we don't have to clone
strings out of it like we did previously (due to taking it by
reference). I also added the metadata ID to the `Metadata` type, so that
we can continue asserting that the metadata's ID matches the expected
one for the field, without having to pass that in separately.

Signed-off-by: Eliza Weisman <eliza@buoyant.io>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants