rails-otel-context 0.9.0 → 0.9.2

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: 592224b44e9a4b7b72a85624dbfea6b05717b629ff9e707a4975cfc6db276b18
4
- data.tar.gz: '0757947daefb592c0ef3e63c4d2396fb049461224c244aa145d51218c9f12f28'
3
+ metadata.gz: 1faef8d7301e399673c55cb396e9ffa42b37d57cee3d3847507ade729bdae453
4
+ data.tar.gz: c0bdf8d4e76eca1a3ebc9081be9ae3b2223a705bcf70df0f7cd50432f04842a5
5
5
  SHA512:
6
- metadata.gz: 1a695932a41348bf86b042b9535b95c9423161ac33873af45539386d3602225de51d430d9d01ac979736742a6cc79377a335d1f2dc07f93281cbdbaf71cfb89d
7
- data.tar.gz: defbc699fa36e0ad33b907965ee6bb4cc47b7190d82acebede64f395bc25534bc6710b59de621f3693e7d33e82be705aa96ad1db95c101dfefdf3efd779089c1
6
+ metadata.gz: 485032935c004f05b919c1e700dfbc69a65e517707709410f70f3e7cd9c3906bc1d8d1594fb1b28bd303885559fdd9e6e11117b25949082a8d8b6ebe13c6a5ee
7
+ data.tar.gz: 4341faef882b6e318b4911d72e369d8f03d5aaf46a720fc3018cf81c9075b8c7e64b2f9d8048e8d388a74da1a67a16273e31022f6bab7aa16c45c02a6bf4a628
@@ -14,10 +14,7 @@ module RailsOtelContext
14
14
 
15
15
  # Runs after config/initializers/ so the OTel SDK tracer_provider is already configured.
16
16
  config.after_initialize do
17
- if OpenTelemetry.tracer_provider.respond_to?(:add_span_processor)
18
- processor = RailsOtelContext::CallContextProcessor.new(app_root: Rails.root)
19
- OpenTelemetry.tracer_provider.add_span_processor(processor)
20
- end
17
+ RailsOtelContext.install_processor!
21
18
 
22
19
  # Warm the table→model map once at boot (after eager_load! in production so
23
20
  # all descendants are available). Without this, the first SQL-named span on a
@@ -39,8 +36,13 @@ module RailsOtelContext
39
36
  # child spans via RequestContext. Also resets the N+1 query counter at both
40
37
  # the start and end of every request to prevent bleed across Puma thread reuse.
41
38
  # Always-on — no config gate.
39
+ #
40
+ # Both hooks are required: ActionController::Base fires :action_controller,
41
+ # ActionController::API (Rails API-only apps) fires :action_controller_api.
42
+ # In Rails 8 API-only apps :action_controller never fires, so without the
43
+ # second hook rails.controller / rails.action would be absent from every span.
42
44
  initializer 'rails_otel_context.install_request_context' do
43
- ActiveSupport.on_load(:action_controller) do
45
+ around_action_hook = proc do
44
46
  around_action do |_controller, block|
45
47
  RailsOtelContext::RequestContext.set(
46
48
  controller: self.class.name,
@@ -51,6 +53,8 @@ module RailsOtelContext
51
53
  RailsOtelContext::RequestContext.clear!
52
54
  end
53
55
  end
56
+ ActiveSupport.on_load(:action_controller, &around_action_hook)
57
+ ActiveSupport.on_load(:action_controller_api, &around_action_hook)
54
58
  end
55
59
 
56
60
  # Capture job class name for every ActiveJob execution and propagate it to all
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailsOtelContext
4
- VERSION = '0.9.0'
4
+ VERSION = '0.9.2'
5
5
  end
@@ -30,6 +30,25 @@ module RailsOtelContext
30
30
  @configuration = Configuration.new
31
31
  end
32
32
 
33
+ # Registers CallContextProcessor with the OTel tracer_provider.
34
+ # Called automatically by the Railtie after_initialize. Call this manually
35
+ # when OpenTelemetry::SDK.configure runs after Rails boot (e.g. in a custom
36
+ # after_initialize block):
37
+ #
38
+ # OpenTelemetry::SDK.configure { |c| c.use_all() }
39
+ # RailsOtelContext.install_processor!
40
+ #
41
+ # Safe to call multiple times — idempotent.
42
+ def install_processor!
43
+ return if @processor_installed
44
+ return unless defined?(Rails) && Rails.root
45
+ return unless OpenTelemetry.tracer_provider.respond_to?(:add_span_processor)
46
+
47
+ @processor_installed = true
48
+ processor = RailsOtelContext::CallContextProcessor.new(app_root: Rails.root)
49
+ OpenTelemetry.tracer_provider.add_span_processor(processor)
50
+ end
51
+
33
52
  # Convenience delegates to FrameContext — see FrameContext for full docs.
34
53
  def with_frame(class_name:, method_name:, &block)
35
54
  FrameContext.with_frame(class_name: class_name, method_name: method_name, &block)
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.9.0
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Last9
@@ -10,35 +10,35 @@ cert_chain: []
10
10
  date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
- name: opentelemetry-api
13
+ name: activerecord
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
16
  - - ">="
17
17
  - !ruby/object:Gem::Version
18
- version: '1.0'
18
+ version: '7.0'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
23
  - - ">="
24
24
  - !ruby/object:Gem::Version
25
- version: '1.0'
25
+ version: '7.0'
26
26
  - !ruby/object:Gem::Dependency
27
- name: railties
27
+ name: opentelemetry-api
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: '7.0'
32
+ version: '1.0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - ">="
38
38
  - !ruby/object:Gem::Version
39
- version: '7.0'
39
+ version: '1.0'
40
40
  - !ruby/object:Gem::Dependency
41
- name: activerecord
41
+ name: railties
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
44
  - - ">="