# Path: google/cloud/sqlalchemy_spanner/_opentelemetry_tracing.py
#     HAS_OPENTELEMETRY_INSTALLED = True
#     HAS_OPENTELEMETRY_INSTALLED = False
# def trace_call(name, extra_attributes=None):
# 
# Path: test/_helpers.py
# class OpenTelemetryBase(fixtures.TestBase):
#     @classmethod
#     def setup_class(cls):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             use_test_ot_exporter()
#             cls.ot_exporter = get_test_ot_exporter()
# 
#     def teardown(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             self.ot_exporter.clear()
# 
#     def assertNoSpans(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             span_list = self.ot_exporter.get_finished_spans()
#             self.assertEqual(len(span_list), 0)
# 
#     def assertSpanAttributes(
#         self, name, status=StatusCode.OK, attributes=None, span=None
#     ):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             if not span:
#                 span_list = self.ot_exporter.get_finished_spans()
#                 self.assertEqual(len(span_list), 1)
#                 span = span_list[0]
# 
#             self.assertEqual(span.name, name)
#             self.assertEqual(span.status.status_code, status)
#             self.assertEqual(dict(span.attributes), attributes)
# 
# HAS_OPENTELEMETRY_INSTALLED = True


import importlib
import mock
import pytest
import sys
    import grpc
    from opentelemetry import trace as trace_api
    from opentelemetry.trace.status import StatusCode
from google.api_core.exceptions import GoogleAPICallError
from google.cloud.spanner_v1 import SpannerClient
from google.cloud.sqlalchemy_spanner import _opentelemetry_tracing
from test._helpers import OpenTelemetryBase, HAS_OPENTELEMETRY_INSTALLED
                    from google.api_core.exceptions import InvalidArgument
            span = span_list[0]
            assert span.kind == trace_api.SpanKind.CLIENT
            span_attr = dict(span.attributes)
            for key in expected_attributes:
                assert key in span_attr
                assert span_attr[key] == expected_attributes[key]
            assert span.name == "CloudSpannerSqlAlchemy.Test"
            assert span.status.status_code == StatusCode.OK

        def test_trace_error(self):
            extra_attributes = {"db.instance": "database_name"}

            expected_attributes = {
                "db.type": "spanner",
                "db.engine": "sqlalchemy_spanner",
                "db.url": SpannerClient.DEFAULT_ENDPOINT,
                "net.host.name": SpannerClient.DEFAULT_ENDPOINT,
            }
            expected_attributes.update(extra_attributes)

            with pytest.raises(GoogleAPICallError):
                with _opentelemetry_tracing.trace_call(
                    "CloudSpannerSqlAlchemy.Test", extra_attributes,
                ) as span:

                    raise _make_rpc_error(InvalidArgument)

            span_list = self.ot_exporter.get_finished_spans()
            assert len(span_list) == 1
            span = span_list[0]

# Path: google/cloud/sqlalchemy_spanner/_opentelemetry_tracing.py
#     HAS_OPENTELEMETRY_INSTALLED = True
#     HAS_OPENTELEMETRY_INSTALLED = False
# def trace_call(name, extra_attributes=None):
# 
# Path: test/_helpers.py
# class OpenTelemetryBase(fixtures.TestBase):
#     @classmethod
#     def setup_class(cls):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             use_test_ot_exporter()
#             cls.ot_exporter = get_test_ot_exporter()
# 
#     def teardown(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             self.ot_exporter.clear()
# 
#     def assertNoSpans(self):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             span_list = self.ot_exporter.get_finished_spans()
#             self.assertEqual(len(span_list), 0)
# 
#     def assertSpanAttributes(
#         self, name, status=StatusCode.OK, attributes=None, span=None
#     ):
#         if HAS_OPENTELEMETRY_INSTALLED:
#             if not span:
#                 span_list = self.ot_exporter.get_finished_spans()
#                 self.assertEqual(len(span_list), 1)
#                 span = span_list[0]
# 
#             self.assertEqual(span.name, name)
#             self.assertEqual(span.status.status_code, status)
#             self.assertEqual(dict(span.attributes), attributes)
# 
# HAS_OPENTELEMETRY_INSTALLED = True


# Path: test/unit/test_opentelemetry_tracing.py
import importlib
import mock
import pytest
import sys
    import grpc
    from opentelemetry import trace as trace_api
    from opentelemetry.trace.status import StatusCode
from google.api_core.exceptions import GoogleAPICallError
from google.cloud.spanner_v1 import SpannerClient
from google.cloud.sqlalchemy_spanner import _opentelemetry_tracing
from test._helpers import OpenTelemetryBase, HAS_OPENTELEMETRY_INSTALLED
                    from google.api_core.exceptions import InvalidArgument

            span = span_list[0]
            assert span.kind == trace_api.SpanKind.CLIENT
            span_attr = dict(span.attributes)
            for key in expected_attributes:
                assert key in span_attr
                assert span_attr[key] == expected_attributes[key]
            assert span.name == "CloudSpannerSqlAlchemy.Test"
            assert span.status.status_code == StatusCode.OK

        def test_trace_error(self):
            extra_attributes = {"db.instance": "database_name"}

            expected_attributes = {
                "db.type": "spanner",
                "db.engine": "sqlalchemy_spanner",
                "db.url": SpannerClient.DEFAULT_ENDPOINT,
                "net.host.name": SpannerClient.DEFAULT_ENDPOINT,
            }
            expected_attributes.update(extra_attributes)

            with pytest.raises(GoogleAPICallError):
                with _opentelemetry_tracing.trace_call(
                    "CloudSpannerSqlAlchemy.Test", extra_attributes,
                ) as span:

                    raise _make_rpc_error(InvalidArgument)

            span_list = self.ot_exporter.get_finished_spans()
            assert len(span_list) == 1
            span = span_list[0]

            assert span.kind == trace_api.SpanKind.CLIENT