rails-otel-context 0.8.1 → 0.8.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3591d00a6587ead8c6abae8400911722b3b7e3802570dd0dcd65abc8ec2c1e79
4
- data.tar.gz: 96fc8db0139458f2baa708e9b518ee70ffb35594257d321390188f6f26c14176
3
+ metadata.gz: 004afd0d90983e7e0acbe3f53e498e9c8583f67cb9d1f0eac650f9d801a7bb6d
4
+ data.tar.gz: 96da00012f2fb29cf86bd99530d9cdaf7be375135612543b29f7acf60e73569e
5
5
  SHA512:
6
- metadata.gz: e3c445ff373ed66d3693a26534090c24a9f1ab737c575a050c935659e575b3c466ab70d03d599d6dd0ef5a555388d7ec36ab5a41ddf496b2eb9a10577a1472d1
7
- data.tar.gz: 3aa56abef92ecca9159f54495a73f73c5d0e57347020d3163318b83135d58e1b308c2565d8cfa1651a33dd865d233601cf0932466e700f88765d130408a58ecb
6
+ metadata.gz: d909cd98bcb6a018a8e957765c3e4ae5bfcf4d583536c3819aa639ec63a7029e81f9cda60e80f2ba7961490a0e6e19d8c32d976dc9f7ee8cc4ef09e035bb5810
7
+ data.tar.gz: 0a6b2433ec72221942b287a584def552ebd59b5857db83d58c41051f75c2a3b23f9aa5380b74db1a08f28d201a5791dfee1ee0254b8d140e8cf55f3c299d1c87
@@ -87,10 +87,16 @@ module RailsOtelContext
87
87
 
88
88
  def start(_name, id, payload)
89
89
  ar_name = payload[:name]
90
- return unless ar_name
91
- return if ar_name == 'SCHEMA' || ar_name.start_with?('CACHE')
90
+ return if ar_name == 'SCHEMA' || ar_name&.start_with?('CACHE')
92
91
 
93
- ctx = if ar_name == 'SQL'
92
+ # Set up slow-query timing regardless of whether we can map a model name,
93
+ # so that raw SQL (connection.execute, SELECT SLEEP, etc.) still sets db.slow.
94
+ if @threshold
95
+ Thread.current[TIMING_ID_KEY] = id
96
+ Thread.current[TIMING_START_KEY] = Process.clock_gettime(Process::CLOCK_MONOTONIC)
97
+ end
98
+
99
+ ctx = if ar_name.nil? || ar_name == 'SQL'
94
100
  ActiveRecordContext.parse_sql_context(payload[:sql])
95
101
  else
96
102
  ActiveRecordContext.parse_ar_name(ar_name)
@@ -109,11 +115,6 @@ module RailsOtelContext
109
115
  ctx[:async] = true if payload[:async]
110
116
  Thread.current[THREAD_KEY] = ctx
111
117
 
112
- if @threshold
113
- Thread.current[TIMING_ID_KEY] = id
114
- Thread.current[TIMING_START_KEY] = Process.clock_gettime(Process::CLOCK_MONOTONIC)
115
- end
116
-
117
118
  # Enrich the current span directly. When OTel instruments via driver-level
118
119
  # prepend (Trilogy, PG, Mysql2), the span is created BEFORE this notification
119
120
  # fires, so CallContextProcessor#on_start sees nil AR context. Applying here
@@ -280,11 +281,14 @@ module RailsOtelContext
280
281
  end
281
282
  return nil unless keyword
282
283
 
283
- table = extract_table_after(sql, keyword)
284
- return nil unless table
284
+ table = extract_table_after(sql, keyword)
285
+ model_name = table ? ar_table_model_map[table] : nil
285
286
 
286
- model_name = ar_table_model_map[table]
287
- return nil unless model_name
287
+ # Fall back to the virtual "SQL" model when the table cannot be resolved
288
+ # (e.g. SELECT SLEEP(0.2), SELECT 1, raw DDL). This lets the span-name
289
+ # formatter produce "SQL.Select" / "SQL.Update" for tab-group purposes
290
+ # instead of leaving the span unnamed.
291
+ model_name ||= 'SQL'
288
292
 
289
293
  { model_name: model_name, method_name: verb,
290
294
  query_key: "#{model_name}.#{verb}".freeze }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsOtelContext
4
- VERSION = '0.8.1'
4
+ VERSION = '0.8.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-otel-context
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.8.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Last9