Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bigtable): respect GOOGLE_CLOUD_CPP_OPENTELEMETRY_TRACING #13748

Merged
merged 1 commit into from
Mar 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions google/cloud/bigtable/internal/defaults.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
#include "google/cloud/internal/getenv.h"
#include "google/cloud/internal/service_endpoint.h"
#include "google/cloud/internal/user_agent_prefix.h"
#include "google/cloud/opentelemetry_options.h"
#include "google/cloud/options.h"
#include "absl/algorithm/container.h"
#include "absl/strings/str_split.h"
Expand Down Expand Up @@ -225,6 +226,10 @@ Options DefaultDataOptions(Options opts) {
if (user_project && !user_project->empty()) {
opts.set<UserProjectOption>(*std::move(user_project));
}
auto tracing = GetEnv("GOOGLE_CLOUD_CPP_OPENTELEMETRY_TRACING");
if (tracing && !tracing->empty()) {
opts.set<OpenTelemetryTracingOption>(true);
}
if (!opts.has<AuthorityOption>()) {
auto ep = google::cloud::internal::UniverseDomainEndpoint(
"bigtable.googleapis.com", opts);
Expand Down
10 changes: 10 additions & 0 deletions google/cloud/bigtable/internal/defaults_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
#include "google/cloud/common_options.h"
#include "google/cloud/grpc_options.h"
#include "google/cloud/internal/background_threads_impl.h"
#include "google/cloud/opentelemetry_options.h"
#include "google/cloud/status.h"
#include "google/cloud/testing_util/chrono_output.h"
#include "google/cloud/testing_util/scoped_environment.h"
Expand Down Expand Up @@ -45,6 +46,8 @@ using mins = std::chrono::minutes;
TEST(OptionsTest, Defaults) {
ScopedEnvironment user_project("GOOGLE_CLOUD_CPP_USER_PROJECT",
absl::nullopt);
ScopedEnvironment tracing("GOOGLE_CLOUD_CPP_OPENTELEMETRY_TRACING",
absl::nullopt);
ScopedEnvironment emulator_host("BIGTABLE_EMULATOR_HOST", absl::nullopt);
ScopedEnvironment instance_emulator_host(
"BIGTABLE_INSTANCE_ADMIN_EMULATOR_HOST", absl::nullopt);
Expand All @@ -57,6 +60,7 @@ TEST(OptionsTest, Defaults) {
EXPECT_EQ(typeid(grpc::GoogleDefaultCredentials()),
typeid(opts.get<GrpcCredentialOption>()));
EXPECT_FALSE(opts.has<UserProjectOption>());
EXPECT_FALSE(opts.has<OpenTelemetryTracingOption>());

auto args = google::cloud::internal::MakeChannelArguments(opts);
// Check that the pool domain is not set by default
Expand Down Expand Up @@ -208,6 +212,12 @@ TEST(OptionsTest, DataUserProjectOption) {
EXPECT_EQ(options.get<UserProjectOption>(), "env-project");
}

TEST(OptionsTest, DataOpenTelemetryOption) {
auto env = ScopedEnvironment("GOOGLE_CLOUD_CPP_OPENTELEMETRY_TRACING", "on");
auto options = DefaultDataOptions(Options{});
EXPECT_TRUE(options.get<OpenTelemetryTracingOption>());
}

TEST(OptionsTest, DataAuthorityOption) {
auto options = DefaultDataOptions(Options{});
EXPECT_EQ(options.get<AuthorityOption>(), "bigtable.googleapis.com");
Expand Down