nhibernate / nhibernate-core

NHibernate Object Relational Mapper
https://nhibernate.info
GNU Lesser General Public License v2.1
2.13k stars 925 forks source link

Telemetry logging is not working when query executed through nhibernate #3493

Closed vishalsharmaeic closed 6 months ago

vishalsharmaeic commented 7 months ago

I'm trying to enable opentelemetry for an application that has a mysql db, mysql has packages to support open telemetry.

When I try executing it without Nhibernate it shows the db.statement in Jaeger UI, but when I execute through NHibernate it shows the db.statement as empty

Here's the implementation that's working without Nhibernate

 using (MySqlConnection connection = new MySqlConnection(connectionString))
 {
     try
     {
         // Opening the connection
         connection.Open();

         string query = "select query";

         using (MySqlCommand cmd = new MySqlCommand(query, connection))
         {
             using (MySqlDataReader reader = cmd.ExecuteReader())
             {
                 while (reader.Read())
                 {
                     value = $"{reader["Domain"]}";
                 }
             }
         }
     }
     catch (Exception ex)
     {
         Console.WriteLine($"Error: {ex.Message}");
     }
 }

Thanks for looking at the issue.

fredericDelaporte commented 7 months ago

There is too little information for a contributor like me to look at this. I have no idea what is opentelemetry, how to set it up in conjunction with MySQL, and I will not invest time in figuring this out. If you could provide a complete test case setting things up and demonstrating the issue, it will be more likely contributors may look at this.

See contributing.

gliljas commented 6 months ago

This is probably due to batching. MySqlConnector seems to not have implemented (opentelemetry) instrumentation of batch commands. An issue could be filed there.

You can disable batching in NHibernate, but the performance may be affected.