@@ -3,12 +3,16 @@ import { TextDocument } from 'vscode-languageserver-textdocument';
33import { SettingsConfigurable , ISettingsSubscriber , SettingsSubscription } from '../settings/ISettingsSubscriber' ;
44import { DefaultSettings , EditorSettings } from '../settings/Settings' ;
55import { LoggerFactory } from '../telemetry/LoggerFactory' ;
6+ import { ScopedTelemetry } from '../telemetry/ScopedTelemetry' ;
7+ import { Telemetry } from '../telemetry/TelemetryDecorator' ;
68import { Delayer } from '../utils/Delayer' ;
7- import { Document } from './Document' ;
9+ import { CloudFormationFileType , Document , DocumentType , Extension } from './Document' ;
810import { DocumentMetadata } from './DocumentProtocol' ;
911
1012export class DocumentManager implements SettingsConfigurable {
1113 private readonly log = LoggerFactory . getLogger ( DocumentManager ) ;
14+
15+ @Telemetry ( ) private readonly telemetry ! : ScopedTelemetry ;
1216 private readonly delayer = new Delayer ( 5 * 1000 ) ;
1317
1418 private editorSettings : EditorSettings = DefaultSettings . editor ;
@@ -21,7 +25,9 @@ export class DocumentManager implements SettingsConfigurable {
2125 private readonly sendDocuments : ( docs : DocumentMetadata [ ] ) => Promise < void > = ( ) => {
2226 return Promise . resolve ( ) ;
2327 } ,
24- ) { }
28+ ) {
29+ this . registerDocumentGauges ( ) ;
30+ }
2531
2632 configure ( settingsManager : ISettingsSubscriber ) : void {
2733 if ( this . settingsSubscription ) {
@@ -125,4 +131,52 @@ export class DocumentManager implements SettingsConfigurable {
125131 this . clearAllStoredIndentation ( ) ;
126132 }
127133 }
134+
135+ private registerDocumentGauges ( ) : void {
136+ this . telemetry . registerGaugeProvider ( 'documents.open.total' , ( ) => this . documentMap . size , {
137+ unit : '1' ,
138+ } ) ;
139+
140+ for ( const type of Object . values ( CloudFormationFileType ) ) {
141+ this . telemetry . registerGaugeProvider (
142+ `documents.open.cfn.type.${ type } ` ,
143+ ( ) => this . countDocumentsByCfnType ( type ) ,
144+ {
145+ unit : '1' ,
146+ } ,
147+ ) ;
148+ }
149+
150+ for ( const type of Object . values ( DocumentType ) ) {
151+ this . telemetry . registerGaugeProvider (
152+ `documents.open.doc.type.${ type } ` ,
153+ ( ) => this . countDocumentsByDocType ( type ) ,
154+ {
155+ unit : '1' ,
156+ } ,
157+ ) ;
158+ }
159+
160+ for ( const type of Object . values ( Extension ) ) {
161+ this . telemetry . registerGaugeProvider (
162+ `documents.open.extension.type.${ type } ` ,
163+ ( ) => this . countDocumentsByExtension ( type ) ,
164+ {
165+ unit : '1' ,
166+ } ,
167+ ) ;
168+ }
169+ }
170+
171+ private countDocumentsByCfnType ( cfnType : CloudFormationFileType ) : number {
172+ return [ ...this . documentMap . values ( ) ] . filter ( ( doc ) => doc . cfnFileType === cfnType ) . length ;
173+ }
174+
175+ private countDocumentsByDocType ( docType : DocumentType ) : number {
176+ return [ ...this . documentMap . values ( ) ] . filter ( ( doc ) => doc . documentType === docType ) . length ;
177+ }
178+
179+ private countDocumentsByExtension ( extension : Extension ) : number {
180+ return [ ...this . documentMap . values ( ) ] . filter ( ( doc ) => doc . extension === extension ) . length ;
181+ }
128182}
0 commit comments