Skip to content

Commit d29001a

Browse files
Merge pull request #537 from nanchen-goog:hide-trace-when-disabled
PiperOrigin-RevId: 990586087
2 parents 4a09597 + 5a85814 commit d29001a

5 files changed

Lines changed: 125 additions & 7 deletions

File tree

‎src/app/components/chat/chat.component.html‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,12 @@
489489
} } @if (appName != "") {
490490
<div class="chat-sub-toolbar">
491491
@if (!(uiEvents().length === 0 && agentReadme && chatType() !== 'eval-result')) {
492-
<mat-button-toggle-group [value]="viewMode()" (change)="onViewModeChange($event.value)" hideSingleSelectionIndicator>
492+
@if (isTraceEnabled()) {
493+
<mat-button-toggle-group [value]="effectiveViewMode()" (change)="onViewModeChange($event.value)" hideSingleSelectionIndicator>
493494
<mat-button-toggle value="events">Events</mat-button-toggle>
494495
<mat-button-toggle value="traces">Traces</mat-button-toggle>
495496
</mat-button-toggle-group>
497+
}
496498

497499
<div class="filter-bar-container" (click)="openAddFilterMenu($event)">
498500
@if (invocationIdFilterActive()) {
@@ -601,7 +603,7 @@
601603
</button>
602604
}
603605

604-
@let hasBranchesOption = viewMode() !== 'traces';
606+
@let hasBranchesOption = effectiveViewMode() !== 'traces';
605607
@let hasStreamingOption = (isTokenStreamingEnabledObs | async) && canEditSession();
606608
@if (hasBranchesOption || hasStreamingOption) {
607609
<button
@@ -684,7 +686,7 @@
684686
(longRunningResponseComplete)="sendMessage($event)"
685687
[sessionName]="sessionId"
686688
[invocationDisplayMap]="invocationDisplayMap()"
687-
[viewMode]="viewMode()"
689+
[viewMode]="effectiveViewMode()"
688690
[shouldShowEvent]="shouldShowEventFn"
689691
(manualScroll)="onManualScroll()"
690692
></app-chat-panel>
@@ -719,7 +721,7 @@
719721
(editFunctionArgs)="editFunctionArgs($event)"
720722
[sessionName]="sessionId"
721723
[invocationDisplayMap]="invocationDisplayMap()"
722-
[viewMode]="viewMode()"
724+
[viewMode]="effectiveViewMode()"
723725
[shouldShowEvent]="shouldShowEventFn"
724726
></app-chat-panel>
725727
}
@@ -825,7 +827,7 @@
825827
[sessionId]="sessionId"
826828
[sessionName]="sessionId"
827829
[invocationDisplayMap]="invocationDisplayMap()"
828-
[viewMode]="viewMode()"
830+
[viewMode]="effectiveViewMode()"
829831
[shouldShowEvent]="shouldShowEventFn"
830832
(manualScroll)="onManualScroll()"
831833
></app-chat-panel>
@@ -880,7 +882,7 @@
880882
(longRunningResponseComplete)="sendMessage($event)"
881883
[sessionName]="sessionId"
882884
[invocationDisplayMap]="invocationDisplayMap()"
883-
[viewMode]="viewMode()"
885+
[viewMode]="effectiveViewMode()"
884886
[shouldShowEvent]="shouldShowEventFn"
885887
(manualScroll)="onManualScroll()"
886888
></app-chat-panel>
@@ -903,7 +905,7 @@
903905
[sessionId]="sessionId"
904906
[sessionName]="sessionId"
905907
[invocationDisplayMap]="invocationDisplayMap()"
906-
[viewMode]="viewMode()"
908+
[viewMode]="effectiveViewMode()"
907909
[shouldShowEvent]="shouldShowEventFn"
908910
(manualScroll)="onManualScroll()"
909911
></app-chat-panel>

‎src/app/components/chat/chat.component.spec.ts‎

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,7 @@ describe('ChatComponent', () => {
228228
mockFeatureFlagService.isInfinityMessageScrollingEnabledResponse.next(
229229
false);
230230
mockFeatureFlagService.isNewSessionButtonEnabledResponse.next(true);
231+
mockFeatureFlagService.isTraceEnabledResponse.next(true);
231232

232233
mockDialog = jasmine.createSpyObj('MatDialog', ['open']);
233234
mockDialog.open.and.returnValue({
@@ -1092,6 +1093,74 @@ describe('ChatComponent', () => {
10921093
});
10931094
});
10941095

1096+
describe('Events/Traces toggle', () => {
1097+
const toggleSelector =
1098+
By.css('.chat-sub-toolbar mat-button-toggle-group');
1099+
1100+
describe('when isTraceEnabled is true', () => {
1101+
beforeEach(() => {
1102+
fixture.detectChanges();
1103+
});
1104+
1105+
it('should be visible', () => {
1106+
expect(fixture.debugElement.query(toggleSelector)).toBeTruthy();
1107+
});
1108+
});
1109+
1110+
describe('when isTraceEnabled is false', () => {
1111+
beforeEach(() => {
1112+
mockFeatureFlagService.isTraceEnabledResponse.next(false);
1113+
fixture.detectChanges();
1114+
});
1115+
1116+
it('should not be visible', () => {
1117+
expect(fixture.debugElement.query(toggleSelector)).toBeFalsy();
1118+
});
1119+
});
1120+
});
1121+
1122+
describe('trace view', () => {
1123+
function chatPanelViewMode() {
1124+
return fixture.debugElement.query(By.directive(ChatPanelComponent))
1125+
.componentInstance.viewMode;
1126+
}
1127+
1128+
describe('when switched to while traces are enabled', () => {
1129+
beforeEach(() => {
1130+
component.switchToTraceView();
1131+
fixture.detectChanges();
1132+
});
1133+
1134+
it('should be shown', () => {
1135+
expect(chatPanelViewMode()).toBe('traces');
1136+
});
1137+
1138+
describe('and traces are then disabled', () => {
1139+
beforeEach(() => {
1140+
mockFeatureFlagService.isTraceEnabledResponse.next(false);
1141+
fixture.detectChanges();
1142+
});
1143+
1144+
it('should fall back to events', () => {
1145+
expect(chatPanelViewMode()).toBe('events');
1146+
});
1147+
});
1148+
});
1149+
1150+
describe('when switched to while traces are disabled', () => {
1151+
beforeEach(() => {
1152+
mockFeatureFlagService.isTraceEnabledResponse.next(false);
1153+
component.switchToTraceView();
1154+
mockFeatureFlagService.isTraceEnabledResponse.next(true);
1155+
fixture.detectChanges();
1156+
});
1157+
1158+
it('should not be selected', () => {
1159+
expect(chatPanelViewMode()).toBe('events');
1160+
});
1161+
});
1162+
});
1163+
10951164
describe('when removeStateUpdate() is called', () => {
10961165
beforeEach(() => {
10971166
component.updatedSessionState.set({[STATE_KEY]: STATE_VALUE});

‎src/app/components/chat/chat.component.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,8 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
341341
protected readonly showBranches = signal(false);
342342
protected readonly expectedUiEvents = signal<UiEvent[]>([]);
343343
protected readonly viewMode = signal<'events' | 'traces'>((this.storageService.getItem('chat-view-mode') as 'events' | 'traces') || 'events');
344+
/** The view shown; a stored `traces` choice is ignored while traces are disabled. */
345+
protected readonly effectiveViewMode = computed(() => this.isTraceEnabled() ? this.viewMode() : 'events');
344346
protected readonly invocationIdFilterActive = signal<boolean>(false);
345347
protected readonly nodePathFilterActive = signal<boolean>(false);
346348
protected readonly invocationIdFilter = signal<string>('');
@@ -800,6 +802,8 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
800802
this.featureFlagService.isNewSessionButtonEnabled();
801803
readonly isEventFilteringEnabled =
802804
toSignal(this.featureFlagService.isEventFilteringEnabled());
805+
readonly isTraceEnabled =
806+
toSignal(this.featureFlagService.isTraceEnabled());
803807
readonly isApplicationSelectorEnabled =
804808
toSignal(this.featureFlagService.isApplicationSelectorEnabled());
805809
readonly isDeleteSessionEnabledObs: Observable<boolean> =
@@ -979,6 +983,7 @@ export class ChatComponent implements OnInit, AfterViewInit, OnDestroy {
979983
}
980984

981985
switchToTraceView() {
986+
if (!this.isTraceEnabled()) return;
982987
this.onViewModeChange('traces');
983988
}
984989

‎src/app/components/event-tab/event-tab.component.ts‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {InfoTable} from '../info-table/info-table';
3030

3131
import {Event, Part} from '../../core/models/types';
3232
import {UI_STATE_SERVICE} from '../../core/services/interfaces/ui-state';
33+
import {FEATURE_FLAG_SERVICE} from '../../core/services/interfaces/feature-flag';
3334
import {SidePanelMessagesInjectionToken} from '../side-panel/side-panel.component.i18n';
3435
import {Span} from '../../core/models/Trace';
3536
import {TRACE_SERVICE} from '../../core/services/interfaces/trace';
@@ -161,12 +162,16 @@ export class EventTabComponent {
161162
protected readonly uiStateService = inject(UI_STATE_SERVICE);
162163
protected readonly traceService = inject(TRACE_SERVICE);
163164
private readonly storageService = inject(STORAGE_SERVICE);
165+
private readonly featureFlagService = inject(FEATURE_FLAG_SERVICE);
164166
readonly i18n = inject(SidePanelMessagesInjectionToken);
165167

166168
readonly isEventRequestResponseLoadingSignal = toSignal(
167169
this.uiStateService.isEventRequestResponseLoading(), {initialValue: false});
170+
readonly isTraceEnabled = toSignal(this.featureFlagService.isTraceEnabled());
168171

172+
// Each span links to the trace view, so none are listed while traces are disabled.
169173
readonly associatedSpans = computed(() => {
174+
if (!this.isTraceEnabled()) return [];
170175
const ev = this.selectedEvent();
171176
if (!ev || !ev.id) return [];
172177

‎src/app/components/side-panel/side-panel.component.spec.ts‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import {of} from 'rxjs';
2929

3030
import {EvalCase} from '../../core/models/Eval';
3131
import {Session} from '../../core/models/Session';
32+
import {GCP_VERTEX_AGENT_EVENT_ID, Span, SpanValidator} from '../../core/models/Trace';
3233
import {AgentService} from '../../core/services/agent.service';
3334
import {ArtifactService} from '../../core/services/artifact.service';
3435
import {AudioRecordingService} from '../../core/services/audio-recording.service';
@@ -72,6 +73,23 @@ const EVAL_TAB_SELECTOR = By.css('app-eval-tab');
7273
const DETAILS_PANEL_CLOSE_BUTTON_SELECTOR =
7374
By.css('.details-panel-container mat-icon');
7475
const EVENT_GRAPH_SELECTOR = By.css('.event-graph-container div');
76+
const SPAN_LINK_SELECTOR = By.css('app-event-tab .span-link');
77+
78+
/** Routes a raw span through `SpanValidator` so `attrEventId` is populated. */
79+
function makeSpan(attributes: Record<string, unknown>): Span {
80+
const result = SpanValidator.safeParse({
81+
name: 'test-span',
82+
trace_id: 'trace-id',
83+
span_id: 'span-id',
84+
start_time: 1,
85+
end_time: 2,
86+
attributes,
87+
});
88+
if (!result.success) {
89+
throw new Error(`Failed to build test span: ${result.error.message}`);
90+
}
91+
return result.data;
92+
}
7593

7694
const EVAL_TAB_INDEX = 3;
7795

@@ -403,6 +421,25 @@ describe('SidePanelComponent', () => {
403421
});
404422
});
405423

424+
describe('associated spans', () => {
425+
beforeEach(() => {
426+
fixture.componentRef.setInput(
427+
'traceData', [makeSpan({[GCP_VERTEX_AGENT_EVENT_ID]: 'event1'})]);
428+
});
429+
430+
it('links the spans of the selected event', () => {
431+
fixture.detectChanges();
432+
expect(fixture.debugElement.queryAll(SPAN_LINK_SELECTOR).length)
433+
.toBe(1);
434+
});
435+
436+
it('links no spans when isTraceEnabled is false', () => {
437+
mockFeatureFlagService.isTraceEnabledResponse.next(false);
438+
fixture.detectChanges();
439+
expect(fixture.debugElement.queryAll(SPAN_LINK_SELECTOR).length)
440+
.toBe(0);
441+
});
442+
});
406443
});
407444

408445
describe('Loading state', () => {

0 commit comments

Comments
 (0)