Change gRPC C Core verbosity during runtime

229 views
Skip to first unread message

Tomer Schwartz

unread,
Dec 7, 2021, 3:38:08 AM12/7/21
to grpc.io
Hi, 

Is it possible to change the verbosity level of the native gRPC C core libraries during runtime
Setting the GRPC_VERBOSITY and GRPC_TRACE as described here, seems to work only if it's done before initialization stages of gRPC C Core. 
To be more specific, we are using Grpc.Core library which is the C# implementation of gRPC based on the native gRPC C-core library. When looking at the C-Core library, I see that in log.cc there is a static member called g_min_severity_to_print, which determines whether gpr_should_log or not, but that member is being set only during gpr_log_verbosity_init(), and that function is called only during initialization (grpc_init() --> grpc_once_init() --> ... --> do_basic_init() --> gpr_log_verbosity_init()).

Thanks,
Tomer.

Tomer Schwartz

unread,
Dec 8, 2021, 5:29:56 AM12/8/21
to grpc.io
I posted this question also on SO, but no replies there as well. I'm actually surprised, as this question should be trivial, no? (either it's supported or not...)
Anyway, here is the call-stack on the server side that triggers the modification of the verbosity level and actually checks the value of the environment variable:
Picture1.png

So this happens following the construction of GrpcEnvironment, but this is a singleton and its ctor is not accessible.
In addition, the method gpr_log_verbosity_init() wasn't declared as external and can't be used from managed code.
Any feedback would be appreciated.

Thanks,
Tomer.
ב-יום שלישי, 7 בדצמבר 2021 בשעה 10:38:08 UTC+2, ‪Tomer Schwartz‬‏ כתב/ה:

Tomer Schwartz

unread,
Dec 13, 2021, 10:12:37 AM12/13/21
to grpc.io
Trying one more time... Can anyone reply on this one?

ב-יום רביעי, 8 בדצמבר 2021 בשעה 12:29:56 UTC+2, ‪Tomer Schwartz‬‏ כתב/ה:

Jan Tattermusch

unread,
Jan 6, 2022, 7:38:45 AM1/6/22
to grpc.io
Sorry, no, it's not possible. The initialization of the native C-core library is non-trivial and changing the debugging level in the native code at runtime is not something we implemented.
If you want, you can provide a custom logger in the managed C# layer (https://github.com/grpc/grpc/blob/master/src/csharp/Grpc.Core/Logging/ILogger.cs) and avoid printing messages at a given verbosity level at runtime, but C-core would still generate those debug messages (which means overhead), you can just prevent them from being printed (not sure if that's helpful in your case).

Tomer Schwartz

unread,
Jan 6, 2022, 3:24:00 PM1/6/22
to grpc.io
Thanks for confirming that Jan. 
That's very helpful.

ב-יום חמישי, 6 בינואר 2022 בשעה 14:38:45 UTC+2, Jan Tattermusch כתב/ה:
Reply all
Reply to author
Forward
0 new messages