From 0a38d039a1685e67a02860746371f99dcc3ef12c Mon Sep 17 00:00:00 2001 From: ben-gawel <167240029+ben-gawel@users.noreply.github.com> Date: Fri, 31 Oct 2025 16:03:39 -0400 Subject: [PATCH] SERVER-112812 Fix invalid access issue when TestData.enableOTELTracing is enabled (#43176) GitOrigin-RevId: 93124538b5a759a9f8c37176462d70c76f79b302 --- src/mongo/otel/traces/bson_text_map_carrier.cpp | 2 +- src/mongo/otel/traces/bson_text_map_carrier.h | 3 +++ src/mongo/otel/traces/bson_text_map_carrier_test.cpp | 4 ++-- src/mongo/shell/utils.js | 7 +++---- 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/mongo/otel/traces/bson_text_map_carrier.cpp b/src/mongo/otel/traces/bson_text_map_carrier.cpp index 34518fc66f9..e96c6bdbd8e 100644 --- a/src/mongo/otel/traces/bson_text_map_carrier.cpp +++ b/src/mongo/otel/traces/bson_text_map_carrier.cpp @@ -47,7 +47,7 @@ BSONTextMapCarrier::BSONTextMapCarrier(const BSONObj& bson) { OtelStringView BSONTextMapCarrier::Get(OtelStringView key) const noexcept { auto it = _values.find(key); if (it == _values.end()) { - return {}; + return kMissingKeyReturnValue; } return it->second; } diff --git a/src/mongo/otel/traces/bson_text_map_carrier.h b/src/mongo/otel/traces/bson_text_map_carrier.h index 21364006d74..0ef0163b0cb 100644 --- a/src/mongo/otel/traces/bson_text_map_carrier.h +++ b/src/mongo/otel/traces/bson_text_map_carrier.h @@ -39,6 +39,9 @@ namespace mongo { namespace otel { namespace traces { +// TODO SERVER-112886: Once this ticket is resolved this should be changed back to an empty string. +constexpr OtelStringView kMissingKeyReturnValue = " "; + using opentelemetry::nostd::function_ref; /** diff --git a/src/mongo/otel/traces/bson_text_map_carrier_test.cpp b/src/mongo/otel/traces/bson_text_map_carrier_test.cpp index c1712056051..5a9b8207865 100644 --- a/src/mongo/otel/traces/bson_text_map_carrier_test.cpp +++ b/src/mongo/otel/traces/bson_text_map_carrier_test.cpp @@ -63,7 +63,7 @@ TEST(BSONTextMapCarrier, GetExistingKey) { TEST(BSONTextMapCarrier, GetMissingKey) { BSONTextMapCarrier carrier; - ASSERT_EQ(carrier.Get(keyA), ""); + ASSERT_EQ(carrier.Get(keyA), kMissingKeyReturnValue); } TEST(BSONTextMapCarrier, SetExistingKey) { @@ -127,7 +127,7 @@ TEST(BSONTextMapCarrier, NonStringFieldsIgnored) { ASSERT_EQ(keys.size(), 1); ASSERT_TRUE(keys.contains(keyA)); ASSERT_EQ(carrier.Get(keyA), valueA); - ASSERT_EQ(carrier.Get("uuid"), ""); + ASSERT_EQ(carrier.Get("uuid"), kMissingKeyReturnValue); } } // namespace diff --git a/src/mongo/shell/utils.js b/src/mongo/shell/utils.js index 2e2bd493983..99bfd634d4d 100644 --- a/src/mongo/shell/utils.js +++ b/src/mongo/shell/utils.js @@ -353,10 +353,9 @@ let _jsTestOptions = {}; function jsTestOptions() { if (TestData) { - // TODO (SERVER-112812): Enable OpenTelemetry tracing. - // const isMultiversion = - // TestData.useRandomBinVersionsWithinReplicaSet || TestData.mixedBinVersions || TestData.mongosBinVersion; - const enableOTELTracing = false; //TestData.enableOTELTracing ?? !isMultiversion; + const isMultiversion = + TestData.useRandomBinVersionsWithinReplicaSet || TestData.mixedBinVersions || TestData.mongosBinVersion; + const enableOTELTracing = TestData.enableOTELTracing ?? !isMultiversion; return Object.merge(_jsTestOptions, { // Test commands should be enabled by default if no enableTestCommands were present in