Skip to content

Conversation

@sinhasubham
Copy link
Contributor

This change enhances observability by introducing these new features:

  1. Cloud Region Attribute: The cloud.region attribute is now added to all OpenTelemetry spans generated by the Spanner client. This provides better geographical context for traces, aiding in performance analysis and debugging across different regions.

  2. Transaction Tag: The transaction_tag set on a Transaction object is now correctly propagated and included in the Commit request. This allows for better end-to-end traceability of transactions.

  3. Request Tag: This introduces support for request_tag on individual Spanner operations like read, execute_sql, and execute_update. When a request_tag is provided in the request_options, it is now added as a spanner.request_tag attribute to the corresponding OpenTelemetry span. This allows for more granular tracing and debugging of specific requests within a transaction or a snapshot.

@sinhasubham sinhasubham requested review from a team as code owners October 27, 2025 06:37
@product-auto-label product-auto-label bot added size: l Pull request size is large. api: spanner Issues related to the googleapis/python-spanner API. labels Oct 27, 2025
@product-auto-label product-auto-label bot added size: xl Pull request size is extra large. and removed size: l Pull request size is large. labels Oct 28, 2025
@harshachinta harshachinta removed their assignment Oct 28, 2025
@sinhasubham sinhasubham self-assigned this Oct 28, 2025
"enable_end_to_end_tracing", enable_end_to_end_tracing
)
db_name = observability_options.get("db_name", db_name)
cloud_region = observability_options.get("cloud_region", cloud_region)
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the use of this ?
IMU, observability_options is something which customers can set and does not have cloud_region property.

db_name = observability_options.get("db_name", db_name)
cloud_region = observability_options.get("cloud_region", cloud_region)

cloud_region = _get_cloud_region()
Copy link
Contributor

Choose a reason for hiding this comment

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

This trace_call method is called for each and every span. Can we call this _get_cloud_region once and save the value as this should not change through the life of application

Copy link
Contributor

Choose a reason for hiding this comment

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

Or handle this in _get_cloud_region method to make call to GoogleCloudResourceDetector only once.

if "request_options" in attributes:
request_options = attributes.pop("request_options")
if request_options and request_options.request_tag:
attributes["spanner.request_tag"] = request_options.request_tag
Copy link
Contributor

Choose a reason for hiding this comment

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

Please use attribute name as request.tag and transaction.tag to be consistent with other languages.

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we also need the same for transaction.tag

# Overwrite the requests timeout for the detector.
# This is necessary as the client will wait the full timeout if the
# code is not run in a GCP environment, with the location endpoints available.
gcp_resource_detector._TIMEOUT_SEC = 0.2
Copy link
Contributor

Choose a reason for hiding this comment

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

Please check if we need this timeout in the new code after refactoring. Currently get region does not have any timeout

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: xl Pull request size is extra large.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants