-
Notifications
You must be signed in to change notification settings - Fork 226
feat: Rack semantic stability opt in #1594
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
131de59
b41a13c
08895b1
0d73d7b
fe46f3d
69239d1
5168831
74aa619
5ad41e3
6dca891
47e65dc
7290822
0752905
b8e0c73
62ce1ca
a99be49
2f7a79d
3cd3c0a
a0dd8ba
a698b3a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,7 +13,8 @@ module Rack | |
| # instrumentation | ||
| class Instrumentation < OpenTelemetry::Instrumentation::Base | ||
| install do |_config| | ||
| require_dependencies | ||
| patch_type = determine_semconv | ||
| send(:"require_dependencies_#{patch_type}") | ||
| end | ||
|
|
||
| present do | ||
|
|
@@ -35,23 +36,62 @@ class Instrumentation < OpenTelemetry::Instrumentation::Base | |
| # | ||
| # @example Default usage | ||
| # Rack::Builder.new do | ||
| # use *OpenTelemetry::Instrumentation::Rack::Instrumenation.instance.middleware_args | ||
| # use *OpenTelemetry::Instrumentation::Rack::Instrumenation.instance.middleware_args_old | ||
| # run lambda { |_arg| [200, { 'Content-Type' => 'text/plain' }, body] } | ||
| # end | ||
| # @return [Array] consisting of a middleware and arguments used in rack builders | ||
| def middleware_args | ||
| if config.fetch(:use_rack_events, false) == true && defined?(OpenTelemetry::Instrumentation::Rack::Middlewares::EventHandler) | ||
| [::Rack::Events, [OpenTelemetry::Instrumentation::Rack::Middlewares::EventHandler.new]] | ||
| def middleware_args_old | ||
|
||
| if config.fetch(:use_rack_events, false) == true && defined?(OpenTelemetry::Instrumentation::Rack::Middlewares::Old::EventHandler) | ||
| [::Rack::Events, [OpenTelemetry::Instrumentation::Rack::Middlewares::Old::EventHandler.new]] | ||
| else | ||
| [OpenTelemetry::Instrumentation::Rack::Middlewares::TracerMiddleware] | ||
| [OpenTelemetry::Instrumentation::Rack::Middlewares::Old::TracerMiddleware] | ||
| end | ||
| end | ||
|
|
||
| def middleware_args_dup | ||
| if config.fetch(:use_rack_events, false) == true && defined?(OpenTelemetry::Instrumentation::Rack::Middlewares::Dup::EventHandler) | ||
| [::Rack::Events, [OpenTelemetry::Instrumentation::Rack::Middlewares::Dup::EventHandler.new]] | ||
| else | ||
| [OpenTelemetry::Instrumentation::Rack::Middlewares::Dup::TracerMiddleware] | ||
| end | ||
| end | ||
|
|
||
| def middleware_args_stable | ||
| if config.fetch(:use_rack_events, false) == true && defined?(OpenTelemetry::Instrumentation::Rack::Middlewares::Stable::EventHandler) | ||
| [::Rack::Events, [OpenTelemetry::Instrumentation::Rack::Middlewares::Stable::EventHandler.new]] | ||
| else | ||
| [OpenTelemetry::Instrumentation::Rack::Middlewares::Stable::TracerMiddleware] | ||
| end | ||
| end | ||
|
|
||
| private | ||
|
|
||
| def require_dependencies | ||
| require_relative 'middlewares/event_handler' if defined?(::Rack::Events) | ||
| require_relative 'middlewares/tracer_middleware' | ||
| def determine_semconv | ||
| stability_opt_in = ENV.fetch('OTEL_SEMCONV_STABILITY_OPT_IN', '') | ||
| values = stability_opt_in.split(',').map(&:strip) | ||
|
|
||
| if values.include?('http/dup') | ||
| 'dup' | ||
| elsif values.include?('http') | ||
| 'stable' | ||
| else | ||
| 'old' | ||
| end | ||
| end | ||
|
|
||
| def require_dependencies_old | ||
| require_relative 'middlewares/old/event_handler' if defined?(::Rack::Events) | ||
| require_relative 'middlewares/old/tracer_middleware' | ||
| end | ||
|
|
||
| def require_dependencies_stable | ||
| require_relative 'middlewares/stable/event_handler' if defined?(::Rack::Events) | ||
| require_relative 'middlewares/stable/tracer_middleware' | ||
| end | ||
|
|
||
| def require_dependencies_dup | ||
| require_relative 'middlewares/dup/event_handler' if defined?(::Rack::Events) | ||
| require_relative 'middlewares/dup/tracer_middleware' | ||
| end | ||
|
|
||
| def config_options(user_config) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.