Skip to content

GetQueryMetrics() does not work if called from RequestHandler #5117

@RamjotSingh

Description

@RamjotSingh

Describe the bug
GetQueryMetrics() does not work if called from RequestHandler. It only works when invoked at the end object (feedIterator output). Making it functional during RequestHandler phase would make it easy to centrally record counters like per partition usage etc.

To Reproduce

    /// <summary>
    /// Telemetry logging handler.
    /// </summary>
    public class TelemetryLoggingHandler : RequestHandler
    {
               /// <summary>
              /// Executes the request on CosmosDB and record telemetry.
             /// </summary>
             /// <param name="request">Request to execute.</param>
             /// <param name="cancellationToken">Cancellation token.</param>
             /// <returns>Task tracking operation.</returns>
             public override async Task<ResponseMessage> SendAsync(RequestMessage request, CancellationToken cancellationToken)
             {
                  ResponseMessage response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);
                  ServerSideCumulativeMetrics queryMetrics = response.Diagnostics?.GetQueryMetrics();
                  // queryMetrics is null here, even though Diagnostics isnt
             }
    }

Expected behavior
GetQueryMetrics() should work when called from RequestHandler

Actual behavior
GetQueryMetrics() does not work if called from RequestHandler.

Environment summary
SDK Version: 3.47.0
OS Version (e.g. Windows, Linux, MacOSX) : Windows

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions