@@ -126,8 +126,8 @@ public Task UpdateViewModelFromQueryAsync(MetricsViewModel viewModel)
126126 {
127127 viewModel . SelectedDuration = _durations . SingleOrDefault ( d => ( int ) d . Id . TotalMinutes == DurationMinutes ) ?? _durations . Single ( d => d . Id == s_defaultDuration ) ;
128128 viewModel . SelectedApplication = _applicationViewModels . GetApplication ( Logger , ApplicationName , canSelectGrouping : true , _selectApplication ) ;
129- var selectedInstance = viewModel . SelectedApplication . Id ? . GetApplicationKey ( ) ;
130- viewModel . Instruments = selectedInstance != null ? TelemetryRepository . GetInstrumentsSummaries ( selectedInstance . Value ) : null ;
129+
130+ UpdateInstruments ( viewModel ) ;
131131
132132 viewModel . SelectedMeter = null ;
133133 viewModel . SelectedInstrument = null ;
@@ -144,6 +144,12 @@ public Task UpdateViewModelFromQueryAsync(MetricsViewModel viewModel)
144144 return Task . CompletedTask ;
145145 }
146146
147+ private void UpdateInstruments ( MetricsViewModel viewModel )
148+ {
149+ var selectedInstance = viewModel . SelectedApplication . Id ? . GetApplicationKey ( ) ;
150+ viewModel . Instruments = selectedInstance != null ? TelemetryRepository . GetInstrumentsSummaries ( selectedInstance . Value ) : null ;
151+ }
152+
147153 private void UpdateApplications ( )
148154 {
149155 _applications = TelemetryRepository . GetApplications ( ) ;
@@ -154,22 +160,26 @@ private void UpdateApplications()
154160
155161 private async Task HandleSelectedApplicationChangedAsync ( )
156162 {
163+ UpdateInstruments ( PageViewModel ) ;
164+
157165 // The new resource might not have the currently selected meter/instrument.
158166 // Check whether the new resource has the current values or not, and clear if they're not available.
159167 if ( PageViewModel . SelectedMeter != null ||
160168 PageViewModel . SelectedInstrument != null )
161169 {
162- var selectedInstance = PageViewModel . SelectedApplication . Id ? . GetApplicationKey ( ) ;
163- var instruments = selectedInstance != null ? TelemetryRepository . GetInstrumentsSummaries ( selectedInstance . Value ) : null ;
164-
165- if ( instruments == null || ShouldClearSelectedMetrics ( instruments ) )
170+ if ( PageViewModel . Instruments == null || ShouldClearSelectedMetrics ( PageViewModel . Instruments ) )
166171 {
167172 PageViewModel . SelectedMeter = null ;
168173 PageViewModel . SelectedInstrument = null ;
169174 }
170175 }
171176
172177 await this . AfterViewModelChangedAsync ( _contentLayout , waitToApplyMobileChange : true ) ;
178+
179+ // The mobile view doesn't update the URL when the application changes.
180+ // Because of this, the page doesn't autoamtically use updated instruments.
181+ // Force the metrics tree to update so it re-renders with the new app's instruments.
182+ _treeMetricSelector ? . OnResourceChanged ( ) ;
173183 }
174184
175185 private bool ShouldClearSelectedMetrics ( List < OtlpInstrumentSummary > instruments )
0 commit comments