Skip to content

Commit 165fdfd

Browse files
committed
Address review feedback
1 parent 6c8bb88 commit 165fdfd

File tree

3 files changed

+15
-35
lines changed

3 files changed

+15
-35
lines changed

google/cloud/spanner_v1/_opentelemetry_tracing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
TRACER_NAME = "cloud.google.com/python/spanner"
3636
TRACER_VERSION = gapic_version.__version__
3737
extended_tracing_globally_disabled = (
38-
os.environ.get("SPANNER_ENABLE_EXTENDED_TRACING", "").lower() == "false"
38+
os.getenv("SPANNER_ENABLE_EXTENDED_TRACING", "").lower() == "false"
3939
)
4040

4141

@@ -68,7 +68,7 @@ def trace_call(name, session, extra_attributes=None, observability_options=None)
6868
# on by default.
6969
enable_extended_tracing = True
7070

71-
if type(observability_options) == dict: # Avoid false positives with mock.Mock
71+
if isinstance(observability_options, dict): # Avoid false positives with mock.Mock
7272
tracer_provider = observability_options.get("tracer_provider", None)
7373
enable_extended_tracing = observability_options.get(
7474
"enable_extended_tracing", enable_extended_tracing

google/cloud/spanner_v1/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class Client(ClientWithProject):
126126
for all ReadRequests and ExecuteSqlRequests that indicates which replicas
127127
or regions should be used for non-transactional reads or queries.
128128
129-
:type labels: dict (str -> any) or None
129+
:type observability_options: dict (str -> any) or None
130130
:param observability_options: (Optional) the configuration to control
131131
the tracer's behavior.
132132
tracer_provider is the injected tracer provider

tests/system/test_observability_options.py

Lines changed: 12 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import mock
1615
import pytest
17-
import unittest
1816

1917
from . import _helpers
20-
from google.cloud.spanner_v1 import Client, DirectedReadOptions
18+
from google.cloud.spanner_v1 import Client
2119

2220
HAS_OTEL_INSTALLED = False
2321

@@ -35,32 +33,20 @@
3533
pass
3634

3735

38-
@pytest.mark.skipif(not HAS_OTEL_INSTALLED, reason="OpenTelemetry needed.")
39-
@pytest.mark.skipif(not _helpers.USE_EMULATOR, reason="Emulator needed.")
36+
@pytest.mark.skipif(
37+
not HAS_OTEL_INSTALLED, reason="OpenTelemetry is necessary to test traces."
38+
)
39+
@pytest.mark.skipif(
40+
not _helpers.USE_EMULATOR, reason="mulator is necessary to test traces."
41+
)
4042
def test_observability_options_propagation():
4143
PROJECT = _helpers.EMULATOR_PROJECT
42-
PATH = "projects/%s" % (PROJECT,)
4344
CONFIGURATION_NAME = "config-name"
4445
INSTANCE_ID = _helpers.INSTANCE_ID
45-
INSTANCE_NAME = "%s/instances/%s" % (PATH, INSTANCE_ID)
4646
DISPLAY_NAME = "display-name"
4747
DATABASE_ID = _helpers.unique_id("temp_db")
4848
NODE_COUNT = 5
49-
PROCESSING_UNITS = 5000
5049
LABELS = {"test": "true"}
51-
TIMEOUT_SECONDS = 80
52-
LEADER_OPTIONS = ["leader1", "leader2"]
53-
DIRECTED_READ_OPTIONS = {
54-
"include_replicas": {
55-
"replica_selections": [
56-
{
57-
"location": "us-west1",
58-
"type_": DirectedReadOptions.ReplicaSelection.Type.READ_ONLY,
59-
},
60-
],
61-
"auto_failover_disabled": True,
62-
},
63-
}
6450

6551
def test_propagation(enable_extended_tracing):
6652
global_tracer_provider = TracerProvider(sampler=ALWAYS_ON)
@@ -95,13 +81,13 @@ def test_propagation(enable_extended_tracing):
9581

9682
try:
9783
instance.create()
98-
except:
84+
except Exception:
9985
pass
10086

10187
db = instance.database(DATABASE_ID)
10288
try:
10389
db.create()
104-
except:
90+
except Exception:
10591
pass
10692

10793
assert db.observability_options == observability_options
@@ -134,7 +120,7 @@ def test_propagation(enable_extended_tracing):
134120
try:
135121
db.delete()
136122
instance.delete()
137-
except:
123+
except Exception:
138124
pass
139125

140126
# Test the respective options for enable_extended_tracing
@@ -143,11 +129,5 @@ def test_propagation(enable_extended_tracing):
143129

144130

145131
def _make_credentials():
146-
import google.auth.credentials
147-
148-
class _CredentialsWithScopes(
149-
google.auth.credentials.Credentials, google.auth.credentials.Scoped
150-
):
151-
pass
152-
153-
return mock.Mock(spec=_CredentialsWithScopes)
132+
from google.auth.credentials import AnonymousCredentials
133+
return AnonymousCredentials()

0 commit comments

Comments
 (0)