| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  | import { PanelPlugin, toOption } from '@grafana/data'; | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  | import { t } from '@grafana/i18n'; | 
					
						
							| 
									
										
										
										
											2022-05-04 00:42:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  | import { getTraceServiceNames, getTraceSpanNames } from '../../../features/explore/TraceView/utils/tags'; | 
					
						
							|  |  |  | import { transformDataFrames } from '../../../features/explore/TraceView/utils/transform'; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | import { TagsEditor } from './TagsEditor'; | 
					
						
							| 
									
										
										
										
											2022-05-04 00:42:36 +08:00
										 |  |  | import { TracesPanel } from './TracesPanel'; | 
					
						
							| 
									
										
										
										
											2024-02-21 21:49:41 +08:00
										 |  |  | import { TracesSuggestionsSupplier } from './suggestions'; | 
					
						
							| 
									
										
										
										
											2022-05-04 00:42:36 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  | export const plugin = new PanelPlugin(TracesPanel) | 
					
						
							|  |  |  |   .setPanelOptions((builder, context) => { | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |     const category = [t('traces.category-span-filters', 'Span filters')]; | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |     const trace = transformDataFrames(context?.data?.[0]); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Find
 | 
					
						
							|  |  |  |     builder | 
					
						
							|  |  |  |       .addTextInput({ | 
					
						
							|  |  |  |         path: 'spanFilters.query', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-find-in-trace', 'Find in trace'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         category, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .addBooleanSwitch({ | 
					
						
							|  |  |  |         path: 'spanFilters.matchesOnly', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-show-matches-only', 'Show matches only'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         defaultValue: false, | 
					
						
							|  |  |  |         category, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .addBooleanSwitch({ | 
					
						
							|  |  |  |         path: 'spanFilters.criticalPathOnly', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-critical-path-only', 'Show critical path only'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         defaultValue: false, | 
					
						
							|  |  |  |         category, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Service name
 | 
					
						
							|  |  |  |     builder | 
					
						
							|  |  |  |       .addSelect({ | 
					
						
							|  |  |  |         path: 'spanFilters.serviceName', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-service-name', 'Service name'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         category, | 
					
						
							|  |  |  |         settings: { | 
					
						
							|  |  |  |           options: trace ? getTraceServiceNames(trace).map(toOption) : [], | 
					
						
							|  |  |  |           allowCustomValue: true, | 
					
						
							|  |  |  |           isClearable: true, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .addRadio({ | 
					
						
							|  |  |  |         path: 'spanFilters.serviceNameOperator', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-service-name-operator', 'Service name operator'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         defaultValue: '=', | 
					
						
							|  |  |  |         settings: { | 
					
						
							|  |  |  |           options: [ | 
					
						
							|  |  |  |             { value: '=', label: '=' }, | 
					
						
							|  |  |  |             { value: '!=', label: '!=' }, | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         category, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Span name
 | 
					
						
							|  |  |  |     builder | 
					
						
							|  |  |  |       .addSelect({ | 
					
						
							|  |  |  |         path: 'spanFilters.spanName', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-span-name', 'Span name'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         category, | 
					
						
							|  |  |  |         settings: { | 
					
						
							|  |  |  |           options: trace ? getTraceSpanNames(trace).map(toOption) : [], | 
					
						
							|  |  |  |           allowCustomValue: true, | 
					
						
							|  |  |  |           isClearable: true, | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .addRadio({ | 
					
						
							|  |  |  |         path: 'spanFilters.spanNameOperator', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-span-name-operator', 'Span name operator'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         defaultValue: '=', | 
					
						
							|  |  |  |         settings: { | 
					
						
							|  |  |  |           options: [ | 
					
						
							|  |  |  |             { value: '=', label: '=' }, | 
					
						
							|  |  |  |             { value: '!=', label: '!=' }, | 
					
						
							|  |  |  |           ], | 
					
						
							|  |  |  |         }, | 
					
						
							|  |  |  |         category, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     // Duration
 | 
					
						
							|  |  |  |     builder | 
					
						
							|  |  |  |       .addTextInput({ | 
					
						
							|  |  |  |         path: 'spanFilters.from', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-min-duration', 'Min duration'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         category, | 
					
						
							|  |  |  |       }) | 
					
						
							|  |  |  |       .addTextInput({ | 
					
						
							|  |  |  |         path: 'spanFilters.to', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |         name: t('traces.name-max-duration', 'Max duration'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |         category, | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     builder.addCustomEditor({ | 
					
						
							|  |  |  |       id: 'tags', | 
					
						
							| 
									
										
										
										
											2025-06-24 19:55:55 +08:00
										 |  |  |       name: t('traces.name-tags', 'Tags'), | 
					
						
							| 
									
										
										
										
											2025-01-10 01:47:07 +08:00
										 |  |  |       path: 'spanFilters', | 
					
						
							|  |  |  |       category, | 
					
						
							|  |  |  |       editor: TagsEditor, | 
					
						
							|  |  |  |       defaultValue: undefined, | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  |   }) | 
					
						
							|  |  |  |   .setSuggestionsSupplier(new TracesSuggestionsSupplier()); |