Skip to content

Instantly share code, notes, and snippets.

@bpatra
Created December 5, 2020 22:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bpatra/83ac0293cb8d830933d66332497a937b to your computer and use it in GitHub Desktop.
Save bpatra/83ac0293cb8d830933d66332497a937b to your computer and use it in GitHub Desktop.
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