Skip to content

Commit 48e1079

Browse files
committed
address comments
1 parent ed3c3b7 commit 48e1079

File tree

6 files changed

+79
-5
lines changed

6 files changed

+79
-5
lines changed

.bazelrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ common:macos --repo_env=BAZEL_NO_APPLE_CPP_TOOLCHAIN=1
5555
test --test_env=GTEST_SHUFFLE --test_env=GTEST_RANDOM_SEED
5656

5757
# By default, build the library with OpenTelemetry
58+
# Enable the config when the bool flag is visible.
59+
# https://github.com/googleapis/google-cloud-cpp-bigquery/issues/98
5860
# build --@com_google_googleapis_google_cloud_cpp//:enable_opentelemetry
5961

6062
# Don't show warnings when building external dependencies. This still shows

google/cloud/bigquery_unified/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ cc_library(
6161
srcs = google_cloud_cpp_bigquery_bigquery_unified_srcs,
6262
hdrs = google_cloud_cpp_bigquery_bigquery_unified_hdrs,
6363
# Enable the config when the bool flag is visible.
64-
# https://github.com/googleapis/google-cloud-cpp/pull/14961
64+
# https://github.com/googleapis/google-cloud-cpp-bigquery/issues/98
6565
# defines = select({
6666
# ":enable_opentelemetry": [
6767
# # Enable OpenTelemetry features in google-cloud-cpp

google/cloud/bigquery_unified/CMakeLists.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,9 +190,11 @@ if (GOOGLE_CLOUD_CPP_BIGQUERY_ENABLE_OPENTELEMETRY)
190190
else ()
191191
message(
192192
FATAL_ERROR
193-
"OpenTelemetry is not enabled in the package "
194-
"google-cloud-cpp, the target "
195-
"google-cloud-cpp::opentelemetry is not available.")
193+
"Instrumentation with OpenTelemetry was requested "
194+
"for google-cloud-cpp-bigquery, but it was not enabled "
195+
"in google-cloud-cpp. Please build and install "
196+
"google-cloud-cpp with GOOGLE_CLOUD_CPP_ENABLE=opentelemetry "
197+
"if you want to use this feature.")
196198
endif ()
197199
endif ()
198200

@@ -255,6 +257,7 @@ function (bigquery_unified_client_define_tests)
255257
set(bigquery_unified_client_unit_tests
256258
# cmake-format: sort
257259
client_test.cc
260+
connection_test.cc
258261
internal/connection_impl_test.cc
259262
internal/default_options_test.cc
260263
internal/tracing_connection_test.cc

google/cloud/bigquery_unified/bigquery_unified_client_unit_tests.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
bigquery_unified_client_unit_tests = [
2020
"client_test.cc",
21+
"connection_test.cc",
2122
"internal/connection_impl_test.cc",
2223
"internal/default_options_test.cc",
2324
"internal/tracing_connection_test.cc",
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include "google/cloud/bigquery_unified/version.h"
16+
#include "google/cloud/bigquery_unified/connection.h"
17+
#include "google/cloud/bigquery_unified/testing_util/opentelemetry_matchers.h"
18+
19+
namespace google::cloud::bigquery_unified {
20+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_BEGIN
21+
namespace {
22+
23+
#ifdef GOOGLE_CLOUD_CPP_BIGQUERY_HAVE_OPENTELEMETRY
24+
using ::google::cloud::bigquery_unified::testing_util::DisableTracing;
25+
using ::google::cloud::bigquery_unified::testing_util::EnableTracing;
26+
using ::google::cloud::bigquery_unified::testing_util::SpanNamed;
27+
using ::testing::Not;
28+
using ::testing::Contains;
29+
30+
TEST(BigQueryUnifiedConnectionTest, TracingEnabled) {
31+
auto span_catcher = testing_util::InstallSpanCatcher();
32+
33+
auto options = EnableTracing(Options{});
34+
auto conn = MakeConnection(std::move(options));
35+
google::cloud::internal::OptionsSpan span(
36+
google::cloud::internal::MergeOptions(Options{}, conn->options()));
37+
// Make a call, which should fail fast. The error itself is not important.
38+
google::cloud::bigquery::v2::GetJobRequest request;
39+
(void)conn->GetJob(request, Options{});
40+
41+
auto spans = span_catcher->GetSpans();
42+
EXPECT_THAT(
43+
spans,
44+
Contains(SpanNamed("bigquery_unified::Connection::GetJob")));
45+
}
46+
47+
TEST(BigQueryUnifiedConnectionTest, TracingDisabled) {
48+
auto span_catcher = testing_util::InstallSpanCatcher();
49+
50+
auto options = DisableTracing(Options{});
51+
auto conn = MakeConnection(std::move(options));
52+
google::cloud::internal::OptionsSpan span(
53+
google::cloud::internal::MergeOptions(Options{}, conn->options()));
54+
// Make a call, which should fail fast. The error itself is not important.
55+
google::cloud::bigquery::v2::GetJobRequest request;
56+
(void)conn->GetJob(request, Options{});
57+
58+
auto spans = span_catcher->GetSpans();
59+
EXPECT_THAT(spans,
60+
Not(Contains(SpanNamed(
61+
"bigquery_unified::Connection::GetJob"))));
62+
}
63+
64+
#endif // GOOGLE_CLOUD_CPP_BIGQUERY_HAVE_OPENTELEMETRY
65+
66+
} // namespace
67+
GOOGLE_CLOUD_CPP_BIGQUERY_INLINE_NAMESPACE_END
68+
} // namespace google::cloud::bigquery_unified

google/cloud/bigquery_unified/testing_util/BUILD.bazel

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ cc_library(
4343
"@google_cloud_cpp//:common",
4444
],
4545
# Enable the config when the bool flag is visible.
46-
# https://github.com/googleapis/google-cloud-cpp/pull/14961
46+
# https://github.com/googleapis/google-cloud-cpp-bigquery/issues/98
4747
# + select({
4848
# ":enable_opentelemetry": [
4949
# "@io_opentelemetry_cpp//exporters/memory:in_memory_span_exporter",

0 commit comments

Comments
 (0)