Skip to content

Conversation

@azkrishpy
Copy link
Contributor

@azkrishpy azkrishpy commented Oct 29, 2025

Issue #, if available:
#806
Description of changes:
Exposes S3 Request Metrics from the CRT S3 Client.

  • S3RequestMetrics: Captures timing, request/response info, and error details for each S3 request attempt
  • onTelemetry() callback: New method in S3MetaRequestResponseHandler invoked after each request completes
  • ErrorType classification: Categorizes errors (SUCCESS, THROTTLING, SERVER_ERROR, CONFIGURED_TIMEOUT, IO, OTHER)

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

return AWS_OP_SUCCESS;
}

static jobject s_get_error_type_enum(JNIEnv *env, int error_code) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll vote for a generic API in the exception class. And replace the isErrorRetryable in HTTP as well

@azkrishpy
Copy link
Contributor Author

Java SDK users can use a custom MetricPublisher that bridges CRT metrics to SDK's MetricCollection:

public class CrtMetricPublisher implements MetricPublisher {
    private final MetricPublisher delegate;

    public CrtMetricPublisher(MetricPublisher delegate) {
        this.delegate = delegate;
    }

    public void publishCrtMetrics(S3RequestMetrics crtMetrics) {
        MetricCollection collection = MetricCollection.builder()
            .name("S3Request")
            .creationTime(Instant.now())
            .putMetric(CoreMetric.API_CALL_DURATION, 
                Duration.ofNanos(crtMetrics.getApiCallDurationNs()))
            .putMetric(CoreMetric.SERVICE_ID, crtMetrics.getServiceId())
            .putMetric(CoreMetric.OPERATION_NAME, crtMetrics.getOperationName())
            .putMetric(CoreMetric.RETRY_COUNT, crtMetrics.getRetryCount())
            .putMetric(CoreMetric.AWS_REQUEST_ID, crtMetrics.getAwsRequestId())
            .putMetric(CoreMetric.AWS_EXTENDED_REQUEST_ID, crtMetrics.getAwsExtendedRequestId())
            .putMetric(CoreMetric.BACKOFF_DELAY_DURATION, 
                Duration.ofNanos(crtMetrics.getBackoffDelayDurationNs()))
            .putMetric(CoreMetric.SERVICE_CALL_DURATION, 
                Duration.ofNanos(crtMetrics.getServiceCallDurationNs()))
            .putMetric(CoreMetric.SIGNING_DURATION, 
                Duration.ofNanos(crtMetrics.getSigningDurationNs()))
            .build();

        delegate.publish(collection);
    }

    @Override
    public void publish(MetricCollection metricCollection) {
        delegate.publish(metricCollection);
    }

    @Override
    public void close() {
        delegate.close();
    }
}

Usage

CrtMetricPublisher metricPublisher = new CrtMetricPublisher(
    LoggingMetricPublisher.create());

S3MetaRequestResponseHandler responseHandler = new S3MetaRequestResponseHandler() {
    @Override
    public void onTelemetry(S3RequestMetrics metrics) {
        metricPublisher.publishCrtMetrics(metrics);
    }

    @Override
    public void onFinished(S3FinishedResponseContext context) {
        // Handle completion
    }
};

S3MetaRequestOptions options = new S3MetaRequestOptions()
    .withMetaRequestType(MetaRequestType.GET_OBJECT)
    .withHttpRequest(httpRequest)
    .withResponseHandler(responseHandler);

try (S3MetaRequest request = client.makeMetaRequest(options)) {
    // Request executes, metrics published via onTelemetry callback
}

@azkrishpy
Copy link
Contributor Author

The following metrics are not available from CRT for java since sdk has the information:

  • CredentialsFetchDuration
  • EndpointResolveDuration
  • MarshallingDuration
  • ServiceEndpoint

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants