getAlby / lndhub.go

Accounting wrapper for the Lightning Network. It provides separate accounts for end-users. (LndHub compatible API written in Go)
GNU General Public License v3.0
86 stars 23 forks source link

add user id to logs as json field #367

Closed kiwiidb closed 1 year ago

kiwiidb commented 1 year ago

Replaces #361

Creates the log middleware with an Enricher and injects it after the JWT middleware. There is some code duplication because of the secured/unsecured API groups, but all in all I think it's ok.

As an example, when trying to pay a misformed invoice

Log output before (no seperate UserID field):

{"level":"error","id":"1ihPmGY73JFRby8AEj7ZHmN6OwiyMclO","time":"2023-05-23T19:34:23+02:00","message":"Invalid payment request user_id:26 error: rpc error: code = Unknown desc = invalid bech32 string length 3"}
{"level":"debug","id":"1ihPmGY73JFRby8AEj7ZHmN6OwiyMclO","remote_ip":"::1","host":"localhost:3000","method":"POST","uri":"/payinvoice","user_agent":"HTTPie/3.2.1","status":400,"referer":"","latency":48.579542,"latency_human":"48.579542ms","bytes_in":"18","bytes_out":"50","time":"2023-05-23T19:34:23+02:00"}

Log output after (UserID JSON field both in the request log and the error log):

{"level":"error","id":"qUX2veARkFzIeojX9s43uuHSSrV0Owhu","UserID":26,"time":"2023-05-23T18:20:19+02:00","message":"Invalid payment request user_id:26 error: rpc error: code = Unknown desc = invalid bech32 string length 3"}
{"level":"debug","id":"qUX2veARkFzIeojX9s43uuHSSrV0Owhu","UserID":26,"remote_ip":"::1","host":"localhost:3000","method":"POST","uri":"/payinvoice","user_agent":"HTTPie/3.2.1","status":400,"referer":"","latency":103.553458,"latency_human":"103.553458ms","bytes_in":"18","bytes_out":"50","time":"2023-05-23T18:20:19+02:00"}
codecov[bot] commented 1 year ago

Codecov Report

Merging #367 (cd7ee1c) into main (db74659) will decrease coverage by 0.07%. The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #367      +/-   ##
==========================================
- Coverage   54.79%   54.72%   -0.07%     
==========================================
  Files          51       51              
  Lines        3190     3194       +4     
==========================================
  Hits         1748     1748              
- Misses       1256     1260       +4     
  Partials      186      186              
Impacted Files Coverage Δ
legacy_endpoints.go 0.00% <0.00%> (ø)
main.go 0.00% <0.00%> (ø)
v2_endpoints.go 0.00% <0.00%> (ø)