这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@sinhasubham
Copy link
Contributor

Note: fix(spanner): resolve TypeError in metrics resource detection

Root cause:
The metrics tracer factory was attempting to access the cloud.region attribute directly from an OpenTelemetry Resource object using dictionary-style subscription (resource['key']).

However, the Resource object is not subscriptable. The correct way to access its attributes is through the .attributes property (resource.attributes['key']).

This change corrects the access pattern, resolving a TypeError that would crash applications upon spanner.Client initialization when built-in metrics were enabled in a GCP environment.

Testing

Tested by replicating the error locally using this script.

@sinhasubham sinhasubham requested review from a team as code owners October 17, 2025 07:55
@product-auto-label product-auto-label bot added the size: xs Pull request size is extra small. label Oct 17, 2025
@product-auto-label product-auto-label bot added api: spanner Issues related to the googleapis/python-spanner API. size: m Pull request size is medium. and removed size: xs Pull request size is extra small. labels Oct 17, 2025
@sinhasubham sinhasubham force-pushed the fix/spanner-metrics-type-error branch from f559b88 to 762d1de Compare October 17, 2025 12:27
DEFAULT_TRANSACTION_OPTIONS = DefaultTransactionOptions(
isolation_level="SERIALIZABLE",
read_lock_mode="PESSIMISTIC",
isolation_level="SERIALIZABLE"
Copy link
Contributor

Choose a reason for hiding this comment

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

why is this required?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change got included by mistake in the PR. I was testing something locally as i felt 'read_lock_mode="PESSIMISTIC"' might not be required here. Removed it for now.

@sinhasubham sinhasubham force-pushed the fix/spanner-metrics-type-error branch from 762d1de to ebb4883 Compare October 17, 2025 16:07
@surbhigarg92 surbhigarg92 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 17, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Oct 17, 2025
SpannerMetricsTracerFactory()
except Exception as e:
log.warning(
"Failed to initialize Spanner built-in metrics. Error: %s", e
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"Failed to initialize Spanner built-in metrics. Error: %s", e
"Failed to initialize Spanner client side metrics. Error: %s", e

@sinhasubham sinhasubham merged commit 7266686 into main Oct 18, 2025
23 checks passed
@sinhasubham sinhasubham deleted the fix/spanner-metrics-type-error branch October 18, 2025 03:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

api: spanner Issues related to the googleapis/python-spanner API. size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants