Skip to content
This repository was archived by the owner on Jul 31, 2023. It is now read-only.

Commit 5762736

Browse files
authored
SpanData::DebugString: Show timestamps, use fewer lines. (#62)
1 parent 66ffd23 commit 5762736

File tree

1 file changed

+23
-45
lines changed

1 file changed

+23
-45
lines changed

opencensus/trace/internal/span_data.cc

Lines changed: 23 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -85,64 +85,42 @@ bool SpanData::has_remote_parent() const { return has_remote_parent_; }
8585

8686
std::string SpanData::DebugString() const {
8787
std::string debug_str;
88-
StrAppend(&debug_str, "Name: ", name(), "\n");
89-
StrAppend(&debug_str, "TraceId-SpanId-Options:\n");
90-
StrAppend(&debug_str, context().ToString(), "\n");
91-
StrAppend(&debug_str, "Parent SpanId: ", parent_span_id().ToHex(), "\n");
92-
93-
// The start time of the span.
94-
StrAppend(&debug_str, "start time: ", absl::FormatTime(start_time()), "\n");
95-
96-
// The end time of the span. Set to 0 if the span hasn't ended.
97-
StrAppend(&debug_str, "end time: ", absl::FormatTime(end_time()), "\n");
98-
99-
// Export Attributes
100-
StrAppend(&debug_str, "Attributes:\n");
101-
// The number of attributes that were dropped.
102-
StrAppend(&debug_str, "\tnum dropped attributes: ", num_attributes_dropped(),
103-
"\n");
88+
StrAppend(&debug_str, "Name: ", name(),
89+
"\nTraceId-SpanId-Options: ", context().ToString(),
90+
"\nParent SpanId: ", parent_span_id().ToHex(),
91+
" (remote: ", has_remote_parent() ? "true" : "false",
92+
")\nStart time: ", absl::FormatTime(start_time()),
93+
"\nEnd time: ", absl::FormatTime(end_time()), "\n");
94+
95+
StrAppend(&debug_str, "Attributes: (", num_attributes_dropped(),
96+
" dropped)\n");
10497
for (const auto& attribute : attributes()) {
105-
StrAppend(&debug_str, "\t", attribute.first, " : ",
106-
attribute.second.DebugString(), "\n");
98+
StrAppend(&debug_str, " \"", attribute.first,
99+
"\":", attribute.second.DebugString(), "\n");
107100
}
108101

109-
// Export Annotations
110-
StrAppend(&debug_str, "Annotations:\n");
111-
StrAppend(&debug_str,
112-
"\tnum dropped annotations: ", annotations().dropped_events_count(),
113-
"\n");
102+
StrAppend(&debug_str, "Annotations: (", annotations().dropped_events_count(),
103+
" dropped)\n");
114104
for (const auto& annotation : annotations().events()) {
115-
StrAppend(&debug_str, "\t", annotation.event().DebugString(), "\n");
105+
StrAppend(&debug_str, " ", absl::FormatTime(annotation.timestamp()), ": ",
106+
annotation.event().DebugString(), "\n");
116107
}
117108

118-
// Export Message Events
119-
StrAppend(&debug_str, "Message Events:\n");
120-
// The number of message events that were dropped.
121-
StrAppend(&debug_str,
122-
"\tnum dropped events: ", message_events().dropped_events_count(),
123-
"\n");
109+
StrAppend(&debug_str, "Message events: (",
110+
message_events().dropped_events_count(), " dropped)\n");
124111
for (const auto& message : message_events().events()) {
125-
StrAppend(&debug_str, "\t", message.event().DebugString(), "\n");
112+
StrAppend(&debug_str, " ", absl::FormatTime(message.timestamp()), ": ",
113+
message.event().DebugString(), "\n");
126114
}
127115

128-
// Export Links
129-
StrAppend(&debug_str, "Links:\n");
130-
// The number of links that were dropped.
131-
StrAppend(&debug_str, "\tnum dropped links: ", num_links_dropped(), "\n");
116+
StrAppend(&debug_str, "Links: (", num_links_dropped(), " dropped)\n");
132117
for (const auto& link : links()) {
133-
StrAppend(&debug_str, "\t", link.DebugString(), "\n");
118+
StrAppend(&debug_str, " ", link.DebugString(), "\n");
134119
}
135120

136-
// True if the span ended.
137-
StrAppend(&debug_str, "span ended: ", (has_ended() ? "true" : "false"), "\n");
121+
StrAppend(&debug_str, "Span ended: ", (has_ended() ? "true" : "false"), "\n");
138122

139-
// True if the parent is on a different process.
140-
StrAppend(&debug_str,
141-
"has remote parent: ", (has_remote_parent() ? "true" : "false"),
142-
"\n");
143-
144-
// The status of the span. Unset if the span hasn't ended.
145-
StrAppend(&debug_str, "status: ", status().ToString(), "\n");
123+
StrAppend(&debug_str, "Status: ", status().ToString(), "\n");
146124
return debug_str;
147125
}
148126

0 commit comments

Comments
 (0)