|
72 | 72 | get_current_span, |
73 | 73 | trace_call, |
74 | 74 | ) |
| 75 | +from google.cloud.spanner_v1.metrics.metrics_capture import MetricsCapture |
75 | 76 |
|
76 | 77 |
|
77 | 78 | SPANNER_DATA_SCOPE = "https://www.googleapis.com/auth/spanner.data" |
@@ -705,7 +706,7 @@ def execute_pdml(): |
705 | 706 | with trace_call( |
706 | 707 | "CloudSpanner.Database.execute_partitioned_pdml", |
707 | 708 | observability_options=self.observability_options, |
708 | | - ) as span: |
| 709 | + ) as span, MetricsCapture(): |
709 | 710 | with SessionCheckout(self._pool) as session: |
710 | 711 | add_span_event(span, "Starting BeginTransaction") |
711 | 712 | txn = api.begin_transaction( |
@@ -912,7 +913,7 @@ def run_in_transaction(self, func, *args, **kw): |
912 | 913 | with trace_call( |
913 | 914 | "CloudSpanner.Database.run_in_transaction", |
914 | 915 | observability_options=observability_options, |
915 | | - ): |
| 916 | + ), MetricsCapture(): |
916 | 917 | # Sanity check: Is there a transaction already running? |
917 | 918 | # If there is, then raise a red flag. Otherwise, mark that this one |
918 | 919 | # is running. |
@@ -1524,7 +1525,7 @@ def generate_read_batches( |
1524 | 1525 | f"CloudSpanner.{type(self).__name__}.generate_read_batches", |
1525 | 1526 | extra_attributes=dict(table=table, columns=columns), |
1526 | 1527 | observability_options=self.observability_options, |
1527 | | - ): |
| 1528 | + ), MetricsCapture(): |
1528 | 1529 | partitions = self._get_snapshot().partition_read( |
1529 | 1530 | table=table, |
1530 | 1531 | columns=columns, |
@@ -1575,7 +1576,7 @@ def process_read_batch( |
1575 | 1576 | with trace_call( |
1576 | 1577 | f"CloudSpanner.{type(self).__name__}.process_read_batch", |
1577 | 1578 | observability_options=observability_options, |
1578 | | - ): |
| 1579 | + ), MetricsCapture(): |
1579 | 1580 | kwargs = copy.deepcopy(batch["read"]) |
1580 | 1581 | keyset_dict = kwargs.pop("keyset") |
1581 | 1582 | kwargs["keyset"] = KeySet._from_dict(keyset_dict) |
@@ -1660,7 +1661,7 @@ def generate_query_batches( |
1660 | 1661 | f"CloudSpanner.{type(self).__name__}.generate_query_batches", |
1661 | 1662 | extra_attributes=dict(sql=sql), |
1662 | 1663 | observability_options=self.observability_options, |
1663 | | - ): |
| 1664 | + ), MetricsCapture(): |
1664 | 1665 | partitions = self._get_snapshot().partition_query( |
1665 | 1666 | sql=sql, |
1666 | 1667 | params=params, |
@@ -1716,7 +1717,7 @@ def process_query_batch( |
1716 | 1717 | with trace_call( |
1717 | 1718 | f"CloudSpanner.{type(self).__name__}.process_query_batch", |
1718 | 1719 | observability_options=self.observability_options, |
1719 | | - ): |
| 1720 | + ), MetricsCapture(): |
1720 | 1721 | return self._get_snapshot().execute_sql( |
1721 | 1722 | partition=batch["partition"], |
1722 | 1723 | **batch["query"], |
@@ -1781,7 +1782,7 @@ def run_partitioned_query( |
1781 | 1782 | f"CloudSpanner.${type(self).__name__}.run_partitioned_query", |
1782 | 1783 | extra_attributes=dict(sql=sql), |
1783 | 1784 | observability_options=self.observability_options, |
1784 | | - ): |
| 1785 | + ), MetricsCapture(): |
1785 | 1786 | partitions = list( |
1786 | 1787 | self.generate_query_batches( |
1787 | 1788 | sql, |
|
0 commit comments