diff --git a/include/grpc/grpc.h b/include/grpc/grpc.h index 5c6cabb3802..dd8a5d7d5f8 100644 --- a/include/grpc/grpc.h +++ b/include/grpc/grpc.h @@ -286,7 +286,8 @@ GRPCAPI grpc_channel* grpc_lame_client_channel_create( /** Close and destroy a grpc channel */ GRPCAPI void grpc_channel_destroy(grpc_channel* channel); -/** Returns the JSON formatted channel trace for this channel. */ +/** Returns the JSON formatted channel trace for this channel. The caller + owns the returned string and is responsible for freeing it. */ GRPCAPI char* grpc_channel_get_trace(grpc_channel* channel); /** Returns the channel uuid, which can be used to look up its trace at a diff --git a/src/core/lib/channel/channel_tracer.cc b/src/core/lib/channel/channel_tracer.cc index 86b7a6cce92..fdb96570cdc 100644 --- a/src/core/lib/channel/channel_tracer.cc +++ b/src/core/lib/channel/channel_tracer.cc @@ -27,6 +27,7 @@ #include #include +#include "src/core/ext/filters/client_channel/status_util.h" #include "src/core/lib/channel/object_registry.h" #include "src/core/lib/gpr/string.h" #include "src/core/lib/gpr/useful.h" @@ -35,12 +36,12 @@ #include "src/core/lib/slice/slice_internal.h" #include "src/core/lib/surface/channel.h" #include "src/core/lib/transport/connectivity_state.h" +#include "src/core/lib/transport/error_utils.h" namespace grpc_core { ChannelTrace::TraceEvent::~TraceEvent() { GRPC_ERROR_UNREF(error_); - referenced_tracer_.reset(); grpc_slice_unref_internal(data_); } @@ -56,7 +57,8 @@ ChannelTrace::ChannelTrace(size_t max_events) gpr_mu_init(&tracer_mu_); channel_uuid_ = grpc_object_registry_register_object( this, GRPC_OBJECT_REGISTRY_CHANNEL_TRACER); - time_created_ = gpr_now(GPR_CLOCK_REALTIME); + time_created_ = grpc_millis_to_timespec(grpc_core::ExecCtx::Get()->Now(), + GPR_CLOCK_REALTIME); } ChannelTrace::~ChannelTrace() { @@ -131,9 +133,20 @@ void ChannelTrace::TraceEvent::RenderTraceEvent(grpc_json* json) { // TODO(ncteisen): Either format this as google.rpc.Status here, or ensure // it is done in the layers above core. if (error_ != GRPC_ERROR_NONE) { - json_iterator = grpc_json_create_child( - json_iterator, json, "status", gpr_strdup(grpc_error_string(error_)), - GRPC_JSON_STRING, true); + grpc_status_code code; + grpc_slice message; + grpc_error_get_status(error_, GRPC_MILLIS_INF_FUTURE, &code, &message, + nullptr, nullptr); + grpc_json* status = grpc_json_create_child( + json_iterator, json, "status", nullptr, GRPC_JSON_OBJECT, false); + json_iterator = grpc_json_create_child(nullptr, status, "code", + grpc_status_code_to_string(code), + GRPC_JSON_STRING, false); + grpc_json_create_child(json_iterator, status, "message", + grpc_slice_to_c_string(message), GRPC_JSON_STRING, + true); + grpc_slice_unref_internal(message); + json_iterator = status; } json_iterator = grpc_json_create_child(json_iterator, json, "timestamp",