55using System . Net ;
66using System . Reflection ;
77using System . Threading . Tasks ;
8- using Microsoft . Azure . Documents ;
9- using Microsoft . Azure . Documents . Client ;
8+ using Microsoft . Azure . Cosmos ;
109using Newtonsoft . Json ;
1110
1211namespace Cosmonaut . Diagnostics
@@ -78,8 +77,8 @@ internal async Task<FeedResponse<TEntity>> InvokeAsync<TEntity>(Func<Task<FeedRe
7877 timer . Start ( ) ;
7978 var result = await eventCall ( ) ;
8079 timer . Stop ( ) ;
81- AddEventMetadataFromHeaders ( result . ResponseHeaders ) ;
82- LogQueryMetricsIfPresent ( result ) ;
80+ AddEventMetadataFromHeaders ( result . Headers ) ;
81+ // LogQueryMetricsIfPresent(result);
8382 TrackSuccess ( timer , HttpStatusCode . OK . ToString ( "D" ) ) ;
8483 return result ;
8584 }
@@ -91,7 +90,7 @@ internal async Task<FeedResponse<TEntity>> InvokeAsync<TEntity>(Func<Task<FeedRe
9190 }
9291 }
9392
94- internal async Task < DocumentResponse < TEntity > > InvokeAsync < TEntity > ( Func < Task < DocumentResponse < TEntity > > > eventCall )
93+ internal async Task < ItemResponse < TEntity > > InvokeAsync < TEntity > ( Func < Task < ItemResponse < TEntity > > > eventCall )
9594 {
9695 if ( ! CosmosEventSource . EventSource . IsEnabled ( ) )
9796 {
@@ -105,7 +104,7 @@ internal async Task<DocumentResponse<TEntity>> InvokeAsync<TEntity>(Func<Task<Do
105104 timer . Start ( ) ;
106105 var result = await eventCall ( ) ;
107106 timer . Stop ( ) ;
108- AddEventMetadataFromHeaders ( result . ResponseHeaders ) ;
107+ AddEventMetadataFromHeaders ( result . Headers ) ;
109108 TrackSuccess ( timer , HttpStatusCode . OK . ToString ( "D" ) ) ;
110109 return result ;
111110 }
@@ -118,7 +117,7 @@ internal async Task<DocumentResponse<TEntity>> InvokeAsync<TEntity>(Func<Task<Do
118117 }
119118 }
120119
121- internal async Task < ResourceResponse < TEntity > > InvokeAsync < TEntity > ( Func < Task < ResourceResponse < TEntity > > > eventCall ) where TEntity : Resource , new ( )
120+ internal async Task < Response < TEntity > > InvokeAsync < TEntity > ( Func < Task < Response < TEntity > > > eventCall )
122121 {
123122 if ( ! CosmosEventSource . EventSource . IsEnabled ( ) )
124123 {
@@ -132,33 +131,7 @@ internal async Task<DocumentResponse<TEntity>> InvokeAsync<TEntity>(Func<Task<Do
132131 timer . Start ( ) ;
133132 var result = await eventCall ( ) ;
134133 timer . Stop ( ) ;
135- AddEventMetadataFromHeaders ( result . ResponseHeaders ) ;
136- TrackSuccess ( timer , result . StatusCode . ToString ( "D" ) ) ;
137- return result ;
138- }
139- catch ( Exception ex )
140- {
141- timer . Stop ( ) ;
142- TrackException ( ex , timer ) ;
143- throw ;
144- }
145- }
146-
147- internal async Task < StoredProcedureResponse < TEntity > > InvokeAsync < TEntity > ( Func < Task < StoredProcedureResponse < TEntity > > > eventCall )
148- {
149- if ( ! CosmosEventSource . EventSource . IsEnabled ( ) )
150- {
151- return await eventCall ( ) ;
152- }
153-
154- var timer = new Stopwatch ( ) ;
155- try
156- {
157- SetPreExecutionEventMetadata ( eventCall ) ;
158- timer . Start ( ) ;
159- var result = await eventCall ( ) ;
160- timer . Stop ( ) ;
161- AddEventMetadataFromHeaders ( result . ResponseHeaders ) ;
134+ AddEventMetadataFromHeaders ( result . Headers ) ;
162135 TrackSuccess ( timer , HttpStatusCode . OK . ToString ( "D" ) ) ;
163136 return result ;
164137 }
@@ -171,13 +144,13 @@ internal async Task<StoredProcedureResponse<TEntity>> InvokeAsync<TEntity>(Func<
171144 }
172145 }
173146
174- private void LogQueryMetricsIfPresent < TEntity > ( FeedResponse < TEntity > result )
175- {
176- if ( result . QueryMetrics == null )
177- return ;
178-
179- EventMetadata . Properties [ nameof ( result . QueryMetrics ) ] = JsonConvert . SerializeObject ( result . QueryMetrics ) ;
180- }
147+ // private void LogQueryMetricsIfPresent<TEntity>(FeedResponse<TEntity> result)
148+ // {
149+ // if (result.QueryMetrics == null)
150+ // return;
151+ //
152+ // EventMetadata.Properties[nameof(result.QueryMetrics)] = JsonConvert.SerializeObject(result.QueryMetrics);
153+ // }
181154
182155 private void SetPreExecutionEventMetadata < TResult > ( Func < Task < TResult > > eventCall )
183156 {
@@ -228,17 +201,17 @@ private void TrackSuccess(Stopwatch timer, string resultCode)
228201
229202 private void AddEventMetadataFromException ( Exception ex )
230203 {
231- if ( ! ( ex is DocumentClientException documentClientException ) )
204+ if ( ! ( ex is CosmosException cosmosException ) )
232205 {
233206 EventMetadata . ResultCode = HttpStatusCode . InternalServerError . ToString ( "D" ) ;
234207 return ;
235208 }
236209
237- AddEventMetadataFromHeaders ( documentClientException . ResponseHeaders ) ;
238- EventMetadata . ResultCode = documentClientException . StatusCode ? . ToString ( "D" ) ?? HttpStatusCode . InternalServerError . ToString ( "D" ) ;
210+ AddEventMetadataFromHeaders ( cosmosException . Headers ) ;
211+ EventMetadata . ResultCode = cosmosException . StatusCode . ToString ( "D" ) ;
239212 }
240213
241- private void AddEventMetadataFromHeaders ( NameValueCollection headers )
214+ private void AddEventMetadataFromHeaders ( Headers headers )
242215 {
243216 if ( headers == null )
244217 return ;
0 commit comments