fix: remove redundant MetricsCapture from trace_call by waiho-gumloop · Pull Request #1522 · googleapis/python-spanner
trace_call() wraps every Spanner operation with a bare MetricsCapture() that creates a MetricsTracer without project_id or instance_id. Since every caller of trace_call already provides its own MetricsCapture with resource_info, this inner one is redundant. The redundant tracer records operation metrics with incomplete resource labels on every operation. Because OpenTelemetry uses cumulative aggregation, these orphan data points persist for the process lifetime and get re-exported every 60 seconds. Cloud Monitoring rejects them with INVALID_ARGUMENT (missing instance_id), producing repeated error logs. Removing the bare MetricsCapture from trace_call eliminates the orphan metric data points entirely. Callers continue to provide their own MetricsCapture(resource_info) with correct labels. Fixes: googleapis#1319