Skip to content

Commit 1a20891

Browse files
authored
Merge pull request #512 from newrelic/vince/live-view-nil-uri
Handle when LiveView meta.uri is nil
2 parents 4507870 + 9e23631 commit 1a20891

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

lib/new_relic/telemetry/phoenix_live_view.ex

+12-4
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ defmodule NewRelic.Telemetry.PhoenixLiveView do
7878

7979
def handle_event(@live_view_mount_start, meas, meta, config) do
8080
if meta.socket.transport_pid do
81-
uri = URI.parse(meta.uri)
81+
{host, path} = parse_uri(meta.uri)
8282

8383
# We're in the LiveView WebSocket process, collect a Transaction
84-
with :collect <- Transaction.Reporter.start_transaction(:web, uri.path) do
84+
with :collect <- Transaction.Reporter.start_transaction(:web, path) do
8585
NewRelic.DistributedTrace.start(:other)
8686
framework_name = "/Phoenix.LiveView/Live/#{inspect(meta.socket.view)}/#{meta.socket.assigns.live_action}"
8787

8888
NewRelic.add_attributes(
8989
pid: inspect(self()),
9090
start_time: meas.system_time,
9191
framework_name: framework_name,
92-
host: uri.host,
93-
path: uri.path,
92+
host: host,
93+
path: path,
9494
"live_view.router": inspect(meta.socket.router),
9595
"live_view.endpoint": inspect(meta.socket.endpoint),
9696
"live_view.action": meta.socket.assigns[:live_action],
@@ -173,4 +173,12 @@ defmodule NewRelic.Telemetry.PhoenixLiveView do
173173
def handle_event(_event, _meas, _meta, _config) do
174174
:ignore
175175
end
176+
177+
defp parse_uri(nil),
178+
do: {"unknown", "unknown"}
179+
180+
defp parse_uri(uri) do
181+
uri = URI.parse(uri)
182+
{uri.host, uri.path}
183+
end
176184
end

0 commit comments

Comments
 (0)