SERVER-112812 Fix invalid access issue when TestData.enableOTELTracing is enabled (#43176)

GitOrigin-RevId: 93124538b5a759a9f8c37176462d70c76f79b302
This commit is contained in:
ben-gawel 2025-10-31 16:03:39 -04:00 committed by MongoDB Bot
parent 6d408e2a5b
commit 0a38d039a1
4 changed files with 9 additions and 7 deletions

View File

@ -47,7 +47,7 @@ BSONTextMapCarrier::BSONTextMapCarrier(const BSONObj& bson) {
OtelStringView BSONTextMapCarrier::Get(OtelStringView key) const noexcept { OtelStringView BSONTextMapCarrier::Get(OtelStringView key) const noexcept {
auto it = _values.find(key); auto it = _values.find(key);
if (it == _values.end()) { if (it == _values.end()) {
return {}; return kMissingKeyReturnValue;
} }
return it->second; return it->second;
} }

View File

@ -39,6 +39,9 @@ namespace mongo {
namespace otel { namespace otel {
namespace traces { 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; using opentelemetry::nostd::function_ref;
/** /**

View File

@ -63,7 +63,7 @@ TEST(BSONTextMapCarrier, GetExistingKey) {
TEST(BSONTextMapCarrier, GetMissingKey) { TEST(BSONTextMapCarrier, GetMissingKey) {
BSONTextMapCarrier carrier; BSONTextMapCarrier carrier;
ASSERT_EQ(carrier.Get(keyA), ""); ASSERT_EQ(carrier.Get(keyA), kMissingKeyReturnValue);
} }
TEST(BSONTextMapCarrier, SetExistingKey) { TEST(BSONTextMapCarrier, SetExistingKey) {
@ -127,7 +127,7 @@ TEST(BSONTextMapCarrier, NonStringFieldsIgnored) {
ASSERT_EQ(keys.size(), 1); ASSERT_EQ(keys.size(), 1);
ASSERT_TRUE(keys.contains(keyA)); ASSERT_TRUE(keys.contains(keyA));
ASSERT_EQ(carrier.Get(keyA), valueA); ASSERT_EQ(carrier.Get(keyA), valueA);
ASSERT_EQ(carrier.Get("uuid"), ""); ASSERT_EQ(carrier.Get("uuid"), kMissingKeyReturnValue);
} }
} // namespace } // namespace

View File

@ -353,10 +353,9 @@ let _jsTestOptions = {};
function jsTestOptions() { function jsTestOptions() {
if (TestData) { if (TestData) {
// TODO (SERVER-112812): Enable OpenTelemetry tracing. const isMultiversion =
// const isMultiversion = TestData.useRandomBinVersionsWithinReplicaSet || TestData.mixedBinVersions || TestData.mongosBinVersion;
// TestData.useRandomBinVersionsWithinReplicaSet || TestData.mixedBinVersions || TestData.mongosBinVersion; const enableOTELTracing = TestData.enableOTELTracing ?? !isMultiversion;
const enableOTELTracing = false; //TestData.enableOTELTracing ?? !isMultiversion;
return Object.merge(_jsTestOptions, { return Object.merge(_jsTestOptions, {
// Test commands should be enabled by default if no enableTestCommands were present in // Test commands should be enabled by default if no enableTestCommands were present in