Module: ReactOnRailsPro::OpenTelemetry
- Defined in:
- lib/react_on_rails_pro/open_telemetry.rb,
sig/react_on_rails_pro/open_telemetry.rbs
Defined Under Namespace
Classes: ClientSpan
Constant Summary collapse
- INSTRUMENTATION_NAME =
"react_on_rails_pro"- SPAN_NAME =
"react_on_rails_pro.renderer_http"- METHOD_ATTRIBUTE =
"http.request.method"- PATH_ATTRIBUTE =
"url.path"- REQUEST_SIZE_ATTRIBUTE =
"http.request.body.size"- RESPONSE_SIZE_ATTRIBUTE =
"http.response.body.size"- STATUS_ATTRIBUTE =
"http.response.status_code"- TRACE_HEADER_NAMES =
%w[traceparent tracestate].freeze
- RENDER_PATH_PATTERN =
%r{\A/bundles/[^/]+/([^/]+)/[0-9a-f]{32}\z}
Class Method Summary collapse
- .body_size(body) ⇒ Integer
- .capture_context ⇒ Object?
- .start_client_span(method, path, parent_context:) ⇒ ClientSpan?
- .with_context(context) { ... } ⇒ Object
Class Method Details
.body_size(body) ⇒ Integer
172 173 174 175 176 177 178 179 |
# File 'lib/react_on_rails_pro/open_telemetry.rb', line 172 def body_size(body) return 0 unless body size = body.bytesize if body.respond_to?(:bytesize) size.is_a?(Integer) ? size : 0 rescue StandardError 0 end |
.capture_context ⇒ Object?
137 138 139 140 141 142 143 |
# File 'lib/react_on_rails_pro/open_telemetry.rb', line 137 def capture_context return unless defined?(::OpenTelemetry::Context) ::OpenTelemetry::Context.current rescue StandardError nil end |
.start_client_span(method, path, parent_context:) ⇒ ClientSpan?
151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'lib/react_on_rails_pro/open_telemetry.rb', line 151 def start_client_span(method, path, parent_context:) provider = configured_tracer_provider return unless provider method_name = method.to_s.upcase span_path = request_path(path) span = provider.tracer(INSTRUMENTATION_NAME).start_span( SPAN_NAME, with_parent: parent_context, kind: :client, attributes: { METHOD_ATTRIBUTE => method_name, PATH_ATTRIBUTE => span_path } ) context = ::OpenTelemetry::Trace.context_with_span(span) ClientSpan.new(span, context) rescue StandardError nil end |
.with_context(context) { ... } ⇒ Object
145 146 147 148 149 |
# File 'lib/react_on_rails_pro/open_telemetry.rb', line 145 def with_context(context, &) return yield unless context ::OpenTelemetry::Context.with_current(context, &) end |