jbogard / MongoDB.Driver.Core.Extensions.DiagnosticSources

Apache License 2.0
46 stars 18 forks source link

Added option to dynamically enable command text based on other command properties #22

Closed ldellisola closed 1 year ago

ldellisola commented 1 year ago

I found myself having huge insert db statements (~3/4 million characters long) in our projects. Those traces were eating up all the storage in our servers and it slowed down tools like Grafana or Jaeger.

I would like to still have the trace data, but to not generate the db.statement tag in these cases. For other operations, their size is relatively small and therefore I want to include the db.statement tag.

The new InstrumentationOptions.ShouldCaptureCommandText option allows for this and it can be overridden by the InstrumentationOptions.CaptureCommandText to maintain compatibility.

jbogard commented 1 year ago

Would another option be a max length?

ldellisola commented 1 year ago

That would work for my specific case, but I think this is a better general approach.

For example, you probably shouldn't be logging all the data inserted into your database as it may have PII such as Full names, addresses, SSN, etc. This modification gives the users of the library more options on which statements will be recorded.

Is there a reason for implementing InstrumentationOptions.MaxLenght over InstrumentationOptions.ShouldCaptureCommandText ?

jbogard commented 1 year ago

I think a better option here might be an activity processor. You can inspect and modify the tag values there. I checked a few other APIs and there aren't really similar kinds of extension points (SQL, HttpClient, etc.). It's an interesting idea but there's already an option to modify arbitrary tag values.