summaryrefslogtreecommitdiff
path: root/lib/gitlab/middleware/correlation_id.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/middleware/correlation_id.rb')
-rw-r--r--lib/gitlab/middleware/correlation_id.rb27
1 files changed, 27 insertions, 0 deletions
diff --git a/lib/gitlab/middleware/correlation_id.rb b/lib/gitlab/middleware/correlation_id.rb
new file mode 100644
index 00000000000..51e2a51ac1b
--- /dev/null
+++ b/lib/gitlab/middleware/correlation_id.rb
@@ -0,0 +1,27 @@
+# A dumb middleware that returns a Go HTML document if the go-get=1 query string
+# is used irrespective if the namespace/project exists
+module Gitlab
+ module Middleware
+ class CorrelationId
+ include ActionView::Helpers::TagHelper
+
+ CORRELATION_HEADER = 'HTTP_CORRELATION_ID'
+
+ def initialize(app)
+ @app = app
+ end
+
+ def call(env)
+ Gitlab::JsonLogger.use_correlation_id(correlation_id) do
+ @app.call(env)
+ end
+ end
+
+ private
+
+ def correlation_id
+ env[CORRELATION_HEADER] || SecureRandom.hex
+ end
+ end
+ end
+end