Class: ActiveRecord::OpenTracing::Processor

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/open_tracing/processor.rb

Constant Summary collapse

DEFAULT_OPERATION_NAME =
"sql.query"
COMPONENT_NAME =
"ActiveRecord"
SPAN_KIND =
"client"
DB_TYPE =
"sql"
QUERY_CATEGORIES =

Used to guess what type of query is running based on the first word of the query

Categories are table: Run an action against a table changes the table metadata or configuration read: Read from the database write: Write or delete records to the database unknown: Can't tell the query action from the first word of the query not_found: First word of the query is not in this list

{
  alter: "table",
  call: "unknown", # run a subquery
  create: "table",
  delete: "write",
  drop: "table",
  do: "read",
  handler: "table", # table metadata
  import: "write",
  insert: "write",
  load: "write", # covers LOAD XML and LOAD DATA queries
  rename: "table",
  replace: "write", # insert, on duplicate overwrite
  select: "read",
  table: "read", # similar to select
  truncate: "table",
  update: "write",
  values: "unknown", # generates rows to use as a table but doesn't hit the database
  with: "unknown" # sets up subqueries in preparation for other queries
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tracer, sanitizer: nil, sql_logging_enabled: true) ⇒ Processor

Returns a new instance of Processor.



42
43
44
45
46
# File 'lib/active_record/open_tracing/processor.rb', line 42

def initialize(tracer, sanitizer: nil, sql_logging_enabled: true)
  @tracer = tracer
  @sanitizer = sanitizer
  @sql_logging_enabled = sql_logging_enabled
end

Instance Attribute Details

#sanitizerObject (readonly)

Returns the value of attribute sanitizer.



40
41
42
# File 'lib/active_record/open_tracing/processor.rb', line 40

def sanitizer
  @sanitizer
end

#sql_logging_enabledObject (readonly)

Returns the value of attribute sql_logging_enabled.



40
41
42
# File 'lib/active_record/open_tracing/processor.rb', line 40

def sql_logging_enabled
  @sql_logging_enabled
end

#tracerObject (readonly)

Returns the value of attribute tracer.



40
41
42
# File 'lib/active_record/open_tracing/processor.rb', line 40

def tracer
  @tracer
end

Instance Method Details

#call(_event_name, start, finish, _id, payload) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/active_record/open_tracing/processor.rb', line 48

def call(_event_name, start, finish, _id, payload)
  span = tracer.start_span(
    payload[:name] || DEFAULT_OPERATION_NAME,
    start_time: start,
    tags: tags_for_payload(payload)
  )

  if (exception = payload[:exception_object])
    span.set_tag("error", true)
    span.log_kv((exception))
  end

  span.finish(end_time: finish)
end