title: How do I record the details of stored procedure calls?
body: <p>In my current project, we are running into issues that could be very easily debugged (in our dev environment) by knowing the calls being made, alongside their respective parameters. In an effort to make that happen, I've established a table which stores the PROC name, as well as some arbitrary JSON blob containing all the parameters with which it was called. I'm also storing call time, but that's irrelevant.</p>
  
  <p>Following is the only way I've found to populate this table:</p>
  
  <pre><code>    DECLARE @prmJson NVARCHAR(MAX) = (  SELECT * FROM (VALUES       
              ('@userId'              ,   @userId                )
          ,   ('@baiCodeMerchantId'   ,   @baiCodeMerchantId     )
          ,   ('@baiCodeMerchantType' ,   @baiCodeMerchantType   )
          ,   ('@appliedAccountId'    ,   @appliedAccountId      )
          ,   ('@unappliedAccountId'  ,   @unappliedAccountId    )) AS P(Name, Value) FOR JSON AUTO);
      INSERT INTO History.SprocCallRecords ([SprocName], [ParametersJson])
      VALUES (QUOTENAME(OBJECT_NAME(@@PROCID)), @prmJson);
  </code></pre>
  
  <p>My issue is, this is a lot of code to add to <em>every single procedure</em>. I'd much rather be able to reflect on the in-scope values, or be able to call some C#-like nameof() method. While I'm obviously projecting other languages onto tSQL, I would very much like to simplify this boilerplate before I integrate it anywhere.</p>
  
  <p>Mostly, I'm looking for suggestions, but there isn't much I was able to find on Google RE: precisely this.</p>
  
  <p>Thanks in advance for any assistance!</p>