This repository was archived by the owner on Mar 31, 2026. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 104
feat: add cloud.region, request_tag and transaction_tag in span attributes #1449
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
e49afa6
feat: add cloud.region and transaction_tag in span attributes
sinhasubham af65849
feat(opentelemetry): add request_tag to span attributes
sinhasubham db90a47
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] 1bd0a2c
feat(opentelemetry): add request_tag to span attributes
sinhasubham f75e31c
🦉 Updates from OwlBot post-processor
gcf-owl-bot[bot] f3bf074
feat(opentelemetry): add request_tag to span attributes
sinhasubham 2ff6bf1
Merge branch 'main' into fix/span-attributes
sinhasubham 8341833
Merge branch 'main' into fix/span-attributes
surbhigarg92 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,20 +18,9 @@ | |
| from .metrics_tracer_factory import MetricsTracerFactory | ||
| import os | ||
| import logging | ||
| from .constants import ( | ||
| SPANNER_SERVICE_NAME, | ||
| GOOGLE_CLOUD_REGION_KEY, | ||
| GOOGLE_CLOUD_REGION_GLOBAL, | ||
| ) | ||
| from .constants import SPANNER_SERVICE_NAME | ||
|
|
||
| try: | ||
| from opentelemetry.resourcedetector import gcp_resource_detector | ||
|
|
||
| # 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 | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes got missed while moving the logic to helper. Added back |
||
|
|
||
| import mmh3 | ||
|
|
||
| logging.getLogger("opentelemetry.resourcedetector.gcp_resource_detector").setLevel( | ||
|
|
@@ -44,6 +33,7 @@ | |
|
|
||
| from .metrics_tracer import MetricsTracer | ||
| from google.cloud.spanner_v1 import __version__ | ||
| from google.cloud.spanner_v1._helpers import _get_cloud_region | ||
| from uuid import uuid4 | ||
|
|
||
| log = logging.getLogger(__name__) | ||
|
|
@@ -86,7 +76,7 @@ def __new__( | |
| cls._metrics_tracer_factory.set_client_hash( | ||
| cls._generate_client_hash(client_uid) | ||
| ) | ||
| cls._metrics_tracer_factory.set_location(cls._get_location()) | ||
| cls._metrics_tracer_factory.set_location(_get_cloud_region()) | ||
| cls._metrics_tracer_factory.gfe_enabled = gfe_enabled | ||
|
|
||
| if cls._metrics_tracer_factory.enabled != enabled: | ||
|
|
@@ -153,28 +143,3 @@ def _generate_client_hash(client_uid: str) -> str: | |
|
|
||
| # Return as 6 digit zero padded hex string | ||
| return f"{sig_figs:06x}" | ||
|
|
||
| @staticmethod | ||
| def _get_location() -> str: | ||
| """Get the location of the resource. | ||
|
|
||
| In case of any error during detection, this method will log a warning | ||
| and default to the "global" location. | ||
|
|
||
| Returns: | ||
| str: The location of the resource. If OpenTelemetry is not installed, returns a global region. | ||
| """ | ||
| if not HAS_OPENTELEMETRY_INSTALLED: | ||
| return GOOGLE_CLOUD_REGION_GLOBAL | ||
| try: | ||
| detector = gcp_resource_detector.GoogleCloudResourceDetector() | ||
| resources = detector.detect() | ||
|
|
||
| if GOOGLE_CLOUD_REGION_KEY in resources.attributes: | ||
| return resources.attributes[GOOGLE_CLOUD_REGION_KEY] | ||
| except Exception as e: | ||
| log.warning( | ||
| "Failed to detect GCP resource location for Spanner metrics, defaulting to 'global'. Error: %s", | ||
| e, | ||
| ) | ||
| return GOOGLE_CLOUD_REGION_GLOBAL | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.