summaryrefslogtreecommitdiff
path: root/config/initializers/0_marginalia.rb
blob: e0e68ce7248c3964e03d0500100494078f23c5e3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# frozen_string_literal: true

require 'marginalia'

::Marginalia::Comment.extend(::Gitlab::Marginalia::Comment)

# By default, PostgreSQL only tracks the first 1024 bytes of a SQL
# query. Prepending the comment allows us to trace the source of the
# query without having to increase the `track_activity_query_size`
# parameter.
#
# We only enable this in production because a number of tests do string
# matching against the raw SQL, and prepending the comment prevents color
# coding from working in the development log.
Marginalia::Comment.prepend_comment = true if Rails.env.production?
Marginalia::Comment.components = [:application, :correlation_id, :jid, :endpoint_id, :db_config_name,
                                  :console_hostname, :console_username]

# As mentioned in https://github.com/basecamp/marginalia/pull/93/files,
# adding :line has some overhead because a regexp on the backtrace has
# to be run on every SQL query. Only enable this in development and test because
# we've seen it slow things down.
if Gitlab.dev_or_test_env?
  Marginalia::Comment.components << :line
  Marginalia::Comment.lines_to_ignore = Regexp.union(
    Gitlab::BacktraceCleaner::IGNORE_BACKTRACES + %w[
      lib/ruby/gems/
      lib/gem_extensions/
      lib/ruby/
      lib/gitlab/marginalia/
      gems/
      lib/gitlab/database/load_balancing/connection_proxy.rb
    ])
end

Gitlab::Marginalia.set_application_name

Gitlab::Marginalia.enable_sidekiq_instrumentation