chore: Record metrics transactions (latency and count)#12051
Draft
chore: Record metrics transactions (latency and count)#12051
Conversation
…count - Add ATTRIBUTES_KEY_STATUS and ATTRIBUTES_KEY_METHOD_NAME to TelemetryConstants - Make MetricsRecorder public with @InternalExtensionOnly annotation - Add MetricsRecorder field and getter to DatastoreOptions - Wire MetricsRecorder into DatastoreImpl for transaction metrics - Refactor TracedReadWriteTransactionCallable to delegate to ReadWriteTransactionCallable - Record per-attempt transaction count with gRPC status code and method name - Record overall transaction latency using Guava Stopwatch - Add unit tests for OpenTelemetryMetricsRecorder, MetricsRecorder, and DatastoreImpl
The per-attempt transaction count should use METHOD_COMMIT (Commit) since each attempt records a commit operation. The overall transaction latency continues to use METHOD_TRANSACTION_RUN (Transaction.Run).
Move extractStatus and extractGrpcStatusCode into a single shared DatastoreException.extractGrpcStatusCode(Throwable) method that walks the exception cause chain. Both call sites in DatastoreImpl now delegate to this shared method.
Rename extractGrpcStatusCode to extractStatusCode and remove the io.grpc.Status dependency. The reason string on DatastoreException is already set from GAX's StatusCode.Code which supports both gRPC and HttpJson transports. Use a plain "UNKNOWN" string as fallback.
Record transaction latency and attempt count at each individual RPC when it involves a transaction: - commit() when isTransactional - lookup() when isTransactional - runQuery() when isTransactional - beginTransaction() (always transactional) - rollback() (always transactional) - AggregationQueryExecutor.execute() when transactional Each RPC uses its own TelemetryConstants.METHOD_* constant. Removed per-attempt recording from ReadWriteTransactionCallable since individual RPCs now handle their own metrics. Made extractStatusCode public for cross-package access from AggregationQueryExecutor.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Initial draft for adding transaction metrics (latency + count)