NClient icon indicating copy to clipboard operation
NClient copied to clipboard

Support capturing diagnostics information using DiagnosticSource

Open smolchanovsky opened this issue 2 years ago • 6 comments

DiagnosticSource is a tool that will allow client users to subscribe to events and use them to log and send metrics. As an example, we can take the Elastic client.

Sample list of events:

  • [ ] NClient.Transport.Request.Start
  • [ ] NClient.Transport.Request.Stop
  • [ ] NClient.Resilience.Attempt.Start
  • [ ] NClient.Resilience.Attempt.Stop
  • [ ] NClient.Exceptions.UnhandledException
  • [ ] NClient.Exceptions.TransportException
  • [ ] NClient.Exceptions.ValidationException
  • [ ] NClient.Exceptions.ArgumentException

Additional links:

  1. A brief introduction to DiagnosticSource
  2. DiagnosticSource User's Guide
  3. DiagnosticSource and DiagnosticListener (docs.microsoft.com)

smolchanovsky avatar Jul 17 '22 21:07 smolchanovsky

Hey! Can I work on this issue?

JorgChrist avatar Aug 04 '22 08:08 JorgChrist

Hi @JorgChrist ! Sure :) I think you'll need ClientInterceptor.cs class. Write if you have any questions, I will be glad to help

smolchanovsky avatar Aug 04 '22 09:08 smolchanovsky

Hello, @JorgChrist! Can I help you with something? Or did you not want to take this issue?

smolchanovsky avatar Aug 26 '22 15:08 smolchanovsky

Hey, @smolchanovsky, sorry for the late reply. I do need some guidance actually.

I know how DiagnosticSource works for the most part and how it's implemented but I'm confused about where shall I implement it in the project!

Sorry, I know this is a newbie problem but I haven't dealt with big projects without guidance before.

JorgChrist avatar Aug 28 '22 14:08 JorgChrist

Hi, @JorgChrist! The project has really become quite large, it seems I need to work on a guide for contributors to make it clearer. Unfortunately, I can't do it right now, because I can't do it fast, but I have good news: you know how DiagnosticSource works, which means you're halfway there :)

I will briefly describe where I would add events:

  • NClient.Transport.Request.* events should be added in TransportNClient class, in this method. This class is responsible for executing requests at the transport layer (usually HTTP).
  • NClient.Resilience.Attempt.* events should be added in the same class, but in an other method.
  • NClient.Exceptions.* events should be added in ClientInterceptor class. All client requests begin and end with this class, so all exceptions are intercepted there.

Thus, it is enough to focus on just two classes: ClientInterceptor and TransportNClient. If you need help or you want me to tell you in more detail how these classes work, write, I will be glad to help.

smolchanovsky avatar Aug 28 '22 23:08 smolchanovsky

Hey @smolchanovsky. Thank you very much for taking the time to explain this! I'm on it and I'll get back to you with feedback when I make some progress :)

JorgChrist avatar Aug 29 '22 05:08 JorgChrist