-
Notifications
You must be signed in to change notification settings - Fork 101
fix(spanner): resolve TypeError in metrics resource detection #1446
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f559b88 to
762d1de
Compare
tests/unit/test_client.py
Outdated
| DEFAULT_TRANSACTION_OPTIONS = DefaultTransactionOptions( | ||
| isolation_level="SERIALIZABLE", | ||
| read_lock_mode="PESSIMISTIC", | ||
| isolation_level="SERIALIZABLE" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why is this required?
There was a problem hiding this comment.
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.
762d1de to
ebb4883
Compare
| SpannerMetricsTracerFactory() | ||
| except Exception as e: | ||
| log.warning( | ||
| "Failed to initialize Spanner built-in metrics. Error: %s", e |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| "Failed to initialize Spanner built-in metrics. Error: %s", e | |
| "Failed to initialize Spanner client side metrics. Error: %s", e |
Note: fix(spanner): resolve TypeError in metrics resource detection
Root cause:
The metrics tracer factory was attempting to access the
cloud.regionattribute directly from an OpenTelemetryResourceobject using dictionary-style subscription (resource['key']).However, the
Resourceobject is not subscriptable. The correct way to access its attributes is through the.attributesproperty (resource.attributes['key']).This change corrects the access pattern, resolving a
TypeErrorthat would crash applications uponspanner.Clientinitialization when built-in metrics were enabled in a GCP environment.Testing
Tested by replicating the error locally using this script.