44 */
55
66import * as vscode from 'vscode'
7+ import { telemetry } from '../../../shared/telemetry/telemetry'
78import { TailLogGroupWizard } from '../wizard/tailLogGroupWizard'
89import { CancellationError } from '../../../shared/utilities/timeoutUtils'
910import { LiveTailSession , LiveTailSessionConfiguration } from '../registry/liveTailSession'
@@ -18,48 +19,70 @@ import { uriToKey } from '../cloudWatchLogsUtils'
1819
1920export async function tailLogGroup (
2021 registry : LiveTailSessionRegistry ,
22+ source : string ,
2123 logData ?: { regionName : string ; groupName : string }
2224) : Promise < void > {
23- const wizard = new TailLogGroupWizard ( logData )
24- const wizardResponse = await wizard . run ( )
25- if ( ! wizardResponse ) {
26- throw new CancellationError ( 'user' )
27- }
28- const awsCredentials = await globals . awsContext . getCredentials ( )
29- if ( awsCredentials === undefined ) {
30- throw new ToolkitError ( 'Failed to start LiveTail session: credentials are undefined.' )
31- }
32- const liveTailSessionConfig : LiveTailSessionConfiguration = {
33- logGroupArn : wizardResponse . regionLogGroupSubmenuResponse . data ,
34- logStreamFilter : wizardResponse . logStreamFilter ,
35- logEventFilterPattern : wizardResponse . filterPattern ,
36- region : wizardResponse . regionLogGroupSubmenuResponse . region ,
37- awsCredentials : awsCredentials ,
38- }
39- const session = new LiveTailSession ( liveTailSessionConfig )
40- if ( registry . has ( uriToKey ( session . uri ) ) ) {
41- await prepareDocument ( session )
42- return
43- }
44- registry . set ( uriToKey ( session . uri ) , session )
25+ await telemetry . cwlLiveTail_Start . run ( async ( span ) => {
26+ const wizard = new TailLogGroupWizard ( logData )
27+ const wizardResponse = await wizard . run ( )
28+ if ( ! wizardResponse ) {
29+ throw new CancellationError ( 'user' )
30+ }
31+ const awsCredentials = await globals . awsContext . getCredentials ( )
32+ if ( awsCredentials === undefined ) {
33+ throw new ToolkitError ( 'Failed to start LiveTail session: credentials are undefined.' )
34+ }
35+ const liveTailSessionConfig : LiveTailSessionConfiguration = {
36+ logGroupArn : wizardResponse . regionLogGroupSubmenuResponse . data ,
37+ logStreamFilter : wizardResponse . logStreamFilter ,
38+ logEventFilterPattern : wizardResponse . filterPattern ,
39+ region : wizardResponse . regionLogGroupSubmenuResponse . region ,
40+ awsCredentials : awsCredentials ,
41+ }
42+ const session = new LiveTailSession ( liveTailSessionConfig )
43+ if ( registry . has ( uriToKey ( session . uri ) ) ) {
44+ await prepareDocument ( session )
45+ span . record ( {
46+ result : 'Succeeded' ,
47+ sessionAlreadyStarted : true ,
48+ source : source ,
49+ } )
50+ return
51+ }
4552
46- const document = await prepareDocument ( session )
53+ registry . set ( uriToKey ( session . uri ) , session )
4754
48- hideShowStatusBarItemsOnActiveEditor ( session , document )
49- registerTabChangeCallback ( session , registry , document )
55+ const document = await prepareDocument ( session )
5056
51- const stream = await session . startLiveTailSession ( )
57+ hideShowStatusBarItemsOnActiveEditor ( session , document )
58+ registerTabChangeCallback ( session , registry , document )
5259
53- await handleSessionStream ( stream , document , session )
60+ const stream = await session . startLiveTailSession ( )
61+ span . record ( {
62+ source : source ,
63+ result : 'Succeeded' ,
64+ sessionAlreadyStarted : false ,
65+ hasLogEventFilterPattern : Boolean ( wizardResponse . filterPattern ) ,
66+ logStreamFilterType : wizardResponse . logStreamFilter . type ,
67+ } )
68+ await handleSessionStream ( stream , document , session )
69+ } )
5470}
5571
56- export function closeSession ( sessionUri : vscode . Uri , registry : LiveTailSessionRegistry ) {
57- const session = registry . get ( uriToKey ( sessionUri ) )
58- if ( session === undefined ) {
59- throw new ToolkitError ( `No LiveTail session found for URI: ${ sessionUri . toString ( ) } ` )
60- }
61- session . stopLiveTailSession ( )
62- registry . delete ( uriToKey ( sessionUri ) )
72+ export function closeSession ( sessionUri : vscode . Uri , registry : LiveTailSessionRegistry , source : string ) {
73+ telemetry . cwlLiveTail_Stop . run ( ( span ) => {
74+ const session = registry . get ( uriToKey ( sessionUri ) )
75+ if ( session === undefined ) {
76+ throw new ToolkitError ( `No LiveTail session found for URI: ${ sessionUri . toString ( ) } ` )
77+ }
78+ session . stopLiveTailSession ( )
79+ registry . delete ( uriToKey ( sessionUri ) )
80+ span . record ( {
81+ result : 'Succeeded' ,
82+ source : source ,
83+ duration : session . getLiveTailSessionDuration ( ) ,
84+ } )
85+ } )
6386}
6487
6588export async function clearDocument ( textDocument : vscode . TextDocument ) {
@@ -215,7 +238,7 @@ function registerTabChangeCallback(
215238 vscode . window . tabGroups . onDidChangeTabs ( ( tabEvent ) => {
216239 const isOpen = isLiveTailSessionOpenInAnyTab ( session )
217240 if ( ! isOpen ) {
218- closeSession ( session . uri , registry )
241+ closeSession ( session . uri , registry , 'ClosedEditors' )
219242 void clearDocument ( document )
220243 }
221244 } )
0 commit comments