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 +4 -4
- data/lib/rails_otel_context/activerecord_context.rb +16 -12
- data/lib/rails_otel_context/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 004afd0d90983e7e0acbe3f53e498e9c8583f67cb9d1f0eac650f9d801a7bb6d
|
|
4
|
+
data.tar.gz: 96da00012f2fb29cf86bd99530d9cdaf7be375135612543b29f7acf60e73569e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
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
|
-
|
|
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
|
|
284
|
-
|
|
284
|
+
table = extract_table_after(sql, keyword)
|
|
285
|
+
model_name = table ? ar_table_model_map[table] : nil
|
|
285
286
|
|
|
286
|
-
|
|
287
|
-
|
|
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 }
|