grpc-dart icon indicating copy to clipboard operation
grpc-dart copied to clipboard

Add logger for debugging

Open stevenroose opened this issue 8 years ago • 12 comments

It would be really great if this package would use a (logging-compliant) logger that could be set to get better reporting when things go wrong.

stevenroose avatar Jan 24 '18 17:01 stevenroose

How are we supposed to debug our apps atm? I'm a bit confused on how this is meant to be used. My server is running, but when something goes wrong, there is no output at all, and I have to start adding try/catch blocks in my code to get the location of the error. Is there another way to do this?

enyo avatar Oct 25 '20 16:10 enyo

@kevmoo do you maybe have some tips for this? I'm really struggling with this.

A typical problem for me is this: Something goes wrong in my server, and my client gets this response:

gRPC Error (code: 2, codeName: UNKNOWN, message: Instance of 'EntityNotFoundException', details: [], rawResponse: null)
  dart:async                                                          _StreamController.addError
  package:grpc/src/client/call.dart 338:16                            ClientCall._responseError
  package:grpc/src/client/call.dart 357:7                             ClientCall._checkForErrorStatus
  package:grpc/src/client/call.dart 448:7                             ClientCall._onResponseDone
  dart:async                                                          _EventSinkWrapper.close
  package:grpc/src/shared/streams.dart 141:10                         _GrpcMessageConversionSink.close
  ===== asynchronous gap ===========================
  dart:async                                                          _BoundSinkStream.listen
  package:grpc/src/client/call.dart 320:54                            ClientCall._onResponseListen
  package:grpc/src/client/call.dart 297:5                             ClientCall._sendRequest
  package:grpc/src/client/call.dart 255:24                            ClientCall.onConnectionReady.<fn>
  ===== asynchronous gap ===========================
  dart:async                                                          Future.then
  etc... etc...

And that's it basically. The server completely "swallows" the Error/Exception and I have to start debugging.

enyo avatar Apr 05 '21 09:04 enyo

@enyo – are you using a Dart server, too?

kevmoo avatar Apr 05 '21 16:04 kevmoo

Yes, I'm only talking about the dart server actually. As in: an exception is thrown in my grpc server code and the grpc library returns a 501 with the exception message but doesn't log anything that I can use to find the error.

enyo avatar Apr 06 '21 11:04 enyo

Ah! That makes sense. CC @mraleph

kevmoo avatar Apr 06 '21 15:04 kevmoo

CC @mit-mit

kevmoo avatar Apr 06 '21 15:04 kevmoo

I don't really have any strong architectural opinion on how to debug. I just sprinkle print's around until I find the problem, but obviously this is not a scalable approach for deployed code.

I think the best I could suggest is to take ServerHandler_ and then add a configurable logging callback which is invoked from all places where _sendError is called. (also some places like _onResponseError should probably be changed to log stack trace as well) (and then add some plumbing so that you could set that callback when you create ServerHandler).

mraleph avatar Apr 06 '21 16:04 mraleph

@mraleph I'm not sure I understand. Are you recommending this approach to be used by me, or is this something you suggest should be implemented to allow for this functionality? I couldn't find any place where ServerHandler could be defined.

enyo avatar Apr 12 '21 10:04 enyo

@enyo I am saying somebody could modify grpc package implementation in the suggested way and expose ability to configure it externally through on Server constructor (similar to how server interceptors are plumbed through Server constructor all the way to ServerHandler_). I would be happy to review and merge such a PR.

mraleph avatar Apr 12 '21 10:04 mraleph

Hi, is there any updates?

fzyzcjy avatar May 02 '22 06:05 fzyzcjy

Linking to some best-practices for GRPC debugging (from the bug or otherwise) could be helpful. I'm currently exploring gRPC and hit some bug I don't understand and wound up here seeking debugging options. :)

eseidel avatar Jun 20 '22 22:06 eseidel

https://github.com/flutter/devtools/issues/2044 points to some other efforts in this area.

eseidel avatar Jun 20 '22 22:06 eseidel