Created
December 5, 2020 22:56
-
-
Save bpatra/83ac0293cb8d830933d66332497a937b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static async Task<FeedResponse<T>> LoggedFeedResponseAsync<T>(this IQueryable<T> queryable, string infoLog, string operationId) | |
{ | |
var docQuery = queryable.AsDocumentQuery(); | |
var now = DateTimeOffset.UtcNow; | |
var watch = Stopwatch.StartNew(); | |
var feedResponse = await docQuery.ExecuteNextAsync<T>(); | |
watch.Stop(); | |
TrackQuery(now, watch.Elapsed, feedResponse.RequestCharge, "read", new TelemetryClient(), infoLog, operationId, feedResponse.ContentLocation); | |
return feedResponse; | |
} | |
public static void TrackQuery(DateTimeOffset start, TimeSpan duration, double requestCharge, string kind, TelemetryClient tc, string infolog, string operationId, string contentLocation) | |
{ | |
var dependency = new DependencyTelemetry( | |
"DOCDB", | |
"", | |
"DOCDB", | |
"", | |
start, | |
duration, | |
"0", // Result code : we can't capture 429 here anyway | |
true // We assume this call is successful, otherwise an exception would be thrown before. | |
); | |
dependency.Metrics["request-charge"] = requestCharge; | |
dependency.Properties["kind"] = kind; | |
dependency.Properties["infolog"] = infolog; | |
dependency.Properties["contentLocation"] = contentLocation ?? ""; | |
if (operationId != null) | |
{ | |
dependency.Context.Operation.Id = operationId; | |
} | |
tc.TrackDependency(dependency); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment