Skip to content

Commit

Permalink
Extract telemetry parameters into a separate method
Browse files Browse the repository at this point in the history
  • Loading branch information
vinistock committed May 31, 2022
1 parent b23da66 commit be9284f
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions lib/ruby_lsp/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,22 +159,35 @@ def respond_with_document_highlight(uri, position)
end

def with_telemetry(request)
params = { request: request[:method], lspVersion: RubyLsp::VERSION }
result = nil
error = nil

request_time = Benchmark.realtime do
result = yield
rescue StandardError => e
params[:errorClass] = e.class.name
params[:errorMessage] = e.message
error = e
end

@writer.write(method: "telemetry/event", params: telemetry_params(request, request_time, error))
result
end

def telemetry_params(request, request_time, error)
uri = request.dig(:params, :textDocument, :uri)
params[:uri] = uri if uri
params[:requestTime] = request_time

@writer.write(method: "telemetry/event", params: params)
result
params = {
request: request[:method],
lspVersion: RubyLsp::VERSION,
requestTime: request_time,
}

if error
params[:errorClass] = error.class.name
params[:errorMessage] = error.message
end

params[:uri] = uri if uri
params
end
end
end

0 comments on commit be9284f

Please sign in to comment.