SERVER-100133 Propagate tracecontext from resmoke to the legacy shell (#43026)

GitOrigin-RevId: b220b1ffa96aab7ac712d97a8ba1b40428e69044
This commit is contained in:
Kruti Shah 2025-10-23 12:19:39 -04:00 committed by MongoDB Bot
parent 2cf5eb1bb5
commit 45cc6f63fb
3 changed files with 18 additions and 8 deletions

View File

@ -10,6 +10,8 @@ import re
import stat
from typing import Any, Optional, Tuple
from opentelemetry import trace
from opentelemetry.trace.propagation.tracecontext import TraceContextTextMapPropagator
from packaging import version
from buildscripts.resmokelib import config, logging, utils
@ -346,6 +348,15 @@ def mongo_shell_program(
global_vars["TestData"] = test_data
if test_data.get("enableOTELTracing", True) and "traceCtx" not in test_data:
current_span = trace.get_current_span()
if current_span:
otelCtx = {}
TraceContextTextMapPropagator().inject(otelCtx)
test_data["traceCtx"] = otelCtx
logger.debug("Mongo Shell: Using trace context %s", otelCtx.get("traceparent"))
if config.EVERGREEN_TASK_ID is not None:
test_data["inEvergreen"] = True
test_data["evergreenTaskId"] = config.EVERGREEN_TASK_ID

View File

@ -175,12 +175,12 @@ Mongo.prototype._setSecurityToken = function (token) {
Mongo.prototype.runCommand = function (dbname, cmd, options) {
let cmdToSend = {...cmd};
if (
jsTestOptions().enableOTELTracing &&
jsTestOptions().traceCtx != null &&
!cmdToSend.hasOwnProperty("$traceCtx")
) {
cmdToSend["$traceCtx"] = {traceparent: jsTestOptions().traceCtx};
if (jsTestOptions().enableOTELTracing && !cmdToSend.hasOwnProperty("$traceCtx")) {
if (jsTestOptions().traceCtx != null) {
cmdToSend["$traceCtx"] = jsTestOptions().traceCtx;
} else {
chatty("WARNING: OTEL tracing enabled but no trace context available.");
}
}
return this._runCommandImpl(dbname, cmdToSend, options, this._securityToken);

View File

@ -474,8 +474,7 @@ function jsTestOptions() {
// TODO (SERVER-112812): Enable OpenTelemetry tracing.
enableOTELTracing: false, // TestData.enableOTELTracing ?? !isMultiversion,
// TODO (SERVER-100133): Replace the mock 'traceCtx' with the actual one from resmoke.
traceCtx: TestData.traceCtx ?? "mockTraceCtx",
traceCtx: TestData.traceCtx || null,
});
}
return _jsTestOptions;