Skip to content

Conversation

@ELLIOTTCABLE
Copy link

@ELLIOTTCABLE ELLIOTTCABLE commented Dec 7, 2023

This PR implements an alternative to #117, making tracing-information non-optional (and thus requiring no build-system changes), instead requiring traits-implementations to be updated to accept the new tracing-information.

This is a breaking change for custom traits-implementations.

The built-in traits implementation use ocaml-trace, if present in the installed world (opam install trace), to generate tracing-spans for each SQL statement.

All of the additions are noops at runtime if the user does not have ocaml-trace installed, and doesn't use a custom traits implementation.

The diff in the generated output is as following:

@@ -7,6 +7,10 @@ module Make (T : Sqlgg_traits.M_io) = struct
   module IO = T.IO
 
   let get_something db ~user_id callback =
+    let __sqlgg_sql = ("SELECT DISTINCT(some_name)\n\
+FROM some_users\n\
+WHERE user_id = ?")
+    in
     let invoke_callback stmt =
       callback
         ~some_name:(T.get_column_Text stmt 0)
@@ -16,12 +20,14 @@ module Make (T : Sqlgg_traits.M_io) = struct
       T.set_param_Int p user_id;
       T.finish_params p
     in
-    T.select db ("SELECT DISTINCT(some_name)\n\
-FROM some_users\n\
-WHERE user_id = ?") set_params invoke_callback
+    T.select ~operation:"SELECT" ~span_name:"get_something" db __sqlgg_sql set_params invoke_callback
 
   module Fold = struct
     let get_something db ~user_id callback acc =

@ELLIOTTCABLE ELLIOTTCABLE changed the title Tracing-via-traits Add debugging-metadata and tracing directly to OCaml traits-module Dec 7, 2023
* upstream/master:
  opam: update
  prepare release 20231201
  Revert "gen_caml: some hygiene"
  gen: ensure no trailing whitespace
  collect params of subqueries
  gen_caml: some hygiene
  build: do not let dune mess up warnings
  sql: + some string functions
  sql: parse generated columns
Copy link
Owner

@ygrek ygrek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • need to finish dune conditional


let select db sql set_params callback =
with_stmt db sql @@ fun stmt ->
let select ?operation ?tables ~span_name db sql set_params callback =
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets put all meta information into one record { tables; span_name; operation }

"db.system", Some system;
"db.statement", Some sql;
"db.operation", operation;
"db.table", Option.map List.hd tables;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

List.hd :sideeye:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants