← Back to Pull requests

SOLR-18682: Continue the caller's trace in Overseer Collection API commands #5405

Open
sarkaramrit1993 opened this pull request with 215 lines diff across 6 files
View on GitHub
sarkaramrit1993 sarkaramrit1993 commented on Nov 28, 2026 13:52 UTC
Author

🤖 Generated with Claude

Description

SOLR-18682: with the Overseer, a traced Collection API request and its command land in unrelated traces, because the ZK queue message carries no trace context. Distributed mode already links them.

Solution

  • The Overseer message carries the caller's trace context as _trace.* keys. TraceAwareCommand parents the command span on it.

  • MODIFYCOLLECTION and CREATEALIAS are skipped, since both treat every message key as data: ModifyCollectionCmd waits for each in state, routed CreateAliasCmd writes them to aliases.json. Other commands only copy prefixed keys (property., router., collection.).
  • Out of scope: traces for those two commands and Config Set API messages.

    Tests

    TestDistributedTracing: one trace for create and delete (fails on main), no span for an unsampled caller, a routed alias stores no trace context. testV2Api.json only re-nests the core reload spans.

    Diff: 215 lines (+152 / -63) across 6 files Reviewer: dsmiley Review duration: 6295m
    All Vouch review confidence checks passed
    Residual risk 0.05 = Change Risk (0.47) × (1 − Review Confidence (0.90)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.47 · 215 lines diff across 6 files
    0.47
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.88 · 5 substantive comment(s)
    0.88
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    90%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.322
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    12 items
    github-actions[bot] github-actions[bot] commented on Nov 28, 2026 14:12 UTC
    Bot

    Automated PR readiness judgements (LLM-generated; may be wrong; not updated on later pushes).

  • ✅ Jira issue in title: already present

  • ⚠️ Changelog — differs from the entry (suggest type: changed; PR has type: fixed): The change modifies the behavior of existing Collection API commands in distributed mode by continuing the caller's trace context instead of starting a new one, which is an improvement to existing behavior rather than a new opt-in feature or bug fix.​

  • ✅ Reference Guide update: not needed <!-- This is an internal improvement to distributed tracing that does not introduce new request parameters&#44; configuration options&#44; or user&#45;facing API changes that require documentation in the Reference Guide&#46;​ -->

  • ✅ Upgrade notes: not needed <!-- The change is backwards&#45;compatible&#59; it explicitly handles older Overseers by skipping trace context injection for specific commands &#40;MODIFYCOLLECTION&#44; CREATEALIAS&#41; to prevent issues during rolling upgrades&#44; and does not remove or rename any public APIs or parameters&#46;​ -->

  • ✅ Tests: included <!-- The PR modifies non&#45;trivial production logic in &#96;CollApiCmds&#46;​java&#96;&#44; &#96;CollectionsHandler&#46;​java&#96;&#44; and &#96;TraceUtils&#46;​java&#96; to handle trace context propagation and cleanup&#44; which warrants new or updated tests to verify the tracing behavior and ensure trace keys are properly stripped from messages&#46;​ -->
  • <!-- Assessed commit e2614604b681ef5d6811e7085ab9e6c64200665b -->

    dsmiley dsmiley commented on code on Nov 28, 2026 19:02 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -148,6 +151,45 @@ public static void injectTraceContext(Request req) {
         textMapPropagator.inject(Context.current(), req, REQUEST_INJECTOR);
       }
     
    +  private static final String MESSAGE_TRACE_PREFIX = "_trace.";
    +
    +  private static final TextMapGetter<ZkNodeProps> MESSAGE_GETTER =
    +      new TextMapGetter<>() {
    +        @Override
    +        public Iterable<String> keys(ZkNodeProps message) {
    +          return message.keySet().stream()
    +              .filter(k -> k.startsWith(MESSAGE_TRACE_PREFIX))
    +              .map(k -> k.substring(MESSAGE_TRACE_PREFIX.length()))
    +              .toList();
    +        }
    +
    +        @Override
    +        public String get(ZkNodeProps message, String key) {
    +          return message.getStr(MESSAGE_TRACE_PREFIX + key);
    +        }
    +      };
    +
    +  /** Adds the current trace context to a Collection API message for the Overseer. */

    other than this javadoc, this method doesn't evoke "Overseer"-ness. The following methods you add don't even do that. Maybe it should just be where the caller is instead of trying to have TraceUtils cross-cut everything.

    CC @stillalex as I believe you did it this way intentionally.

    dsmiley dsmiley commented on code on Nov 28, 2026 19:05 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -148,6 +151,45 @@ public static void injectTraceContext(Request req) {
         textMapPropagator.inject(Context.current(), req, REQUEST_INJECTOR);
       }
     
    +  private static final String MESSAGE_TRACE_PREFIX = "_trace.";
    +
    +  private static final TextMapGetter<ZkNodeProps> MESSAGE_GETTER =
    +      new TextMapGetter<>() {
    +        @Override
    +        public Iterable<String> keys(ZkNodeProps message) {
    +          return message.keySet().stream()
    +              .filter(k -> k.startsWith(MESSAGE_TRACE_PREFIX))
    +              .map(k -> k.substring(MESSAGE_TRACE_PREFIX.length()))
    +              .toList();
    +        }
    +
    +        @Override
    +        public String get(ZkNodeProps message, String key) {
    +          return message.getStr(MESSAGE_TRACE_PREFIX + key);
    +        }
    +      };
    +
    +  /** Adds the current trace context to a Collection API message for the Overseer. */
    +  public static void injectTraceContext(Map<String, Object> message) {
    +    if (Span.current().getSpanContext().isValid()) {
    +      getTextMapPropagator()
    +          .inject(Context.current(), message, (m, k, v) -> m.put(MESSAGE_TRACE_PREFIX + k, v));
    +    }
    +  }
    +
    +  /** Reads the trace context added by {@link #injectTraceContext(Map)}, if any. */
    +  public static Context extractTraceContext(ZkNodeProps message) {
    +    return getTextMapPropagator().extract(Context.current(), message, MESSAGE_GETTER);
    +  }
    +
    +  /** Returns the message without the keys added by {@link #injectTraceContext(Map)}. */
    +  public static ZkNodeProps removeTraceContext(ZkNodeProps message) {

    is it really so bad to leave the trace context there?

    dsmiley dsmiley commented on code on Nov 28, 2026 19:07 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -172,11 +214,15 @@ public static void setOperations(SolrQueryRequest req, String clazz, List<String
       }
     
       public static Span startCollectionApiCommandSpan(
    -      String name, String collection, boolean isAsync) {
    +      String name, String collection, boolean isAsync, Context parent) {
         Tracer tracer = getGlobalTracer();
         SpanKind kind = isAsync ? SpanKind.PRODUCER : SpanKind.CLIENT;

    I suppose SpanKind.CLIENT would only make sense for Overseer processing, but not for disabled Overseer

    dsmiley dsmiley commented on code on Nov 28, 2026 19:09 UTC
    Code Review
    solr/modules/opentelemetry/src/test-files/solr/tracing/TestDistributedTracing/testV2Api.json:1
    @@ -1,57 +1,56 @@
     {"phases":[
         {
           "description":"phase 0",
    -      "spans":[
    -        {
    -          "name":"ReloadCollectionCmd",
    -          "kind":"CLIENT",
    -          "db.instance":"collection1",
    -          "children":[
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard1_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"},
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard1_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"},
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard2_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"},
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard2_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"}]},
    -        {
    +      "spans":[{

    hmm; the indentation style is different, which isn't good for diff'ing

    dsmiley dsmiley commented on Nov 28, 2026 19:18 UTC
    Reviewer

    thanks

    sarkaramrit1993 sarkaramrit1993 commented on code on Nov 30, 2026 10:29 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -148,6 +151,45 @@ public static void injectTraceContext(Request req) {
         textMapPropagator.inject(Context.current(), req, REQUEST_INJECTOR);
       }
     
    +  private static final String MESSAGE_TRACE_PREFIX = "_trace.";
    +
    +  private static final TextMapGetter<ZkNodeProps> MESSAGE_GETTER =
    +      new TextMapGetter<>() {
    +        @Override
    +        public Iterable<String> keys(ZkNodeProps message) {
    +          return message.keySet().stream()
    +              .filter(k -> k.startsWith(MESSAGE_TRACE_PREFIX))
    +              .map(k -> k.substring(MESSAGE_TRACE_PREFIX.length()))
    +              .toList();
    +        }
    +
    +        @Override
    +        public String get(ZkNodeProps message, String key) {
    +          return message.getStr(MESSAGE_TRACE_PREFIX + key);
    +        }
    +      };
    +
    +  /** Adds the current trace context to a Collection API message for the Overseer. */

    Thanks @dsmiley, good point. I moved the message helpers into TraceAwareCommand, next to where they're used, so TraceUtils only gains the parent arg.

    sarkaramrit1993 sarkaramrit1993 commented on code on Nov 30, 2026 10:29 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -148,6 +151,45 @@ public static void injectTraceContext(Request req) {
         textMapPropagator.inject(Context.current(), req, REQUEST_INJECTOR);
       }
     
    +  private static final String MESSAGE_TRACE_PREFIX = "_trace.";
    +
    +  private static final TextMapGetter<ZkNodeProps> MESSAGE_GETTER =
    +      new TextMapGetter<>() {
    +        @Override
    +        public Iterable<String> keys(ZkNodeProps message) {
    +          return message.keySet().stream()
    +              .filter(k -> k.startsWith(MESSAGE_TRACE_PREFIX))
    +              .map(k -> k.substring(MESSAGE_TRACE_PREFIX.length()))
    +              .toList();
    +        }
    +
    +        @Override
    +        public String get(ZkNodeProps message, String key) {
    +          return message.getStr(MESSAGE_TRACE_PREFIX + key);
    +        }
    +      };
    +
    +  /** Adds the current trace context to a Collection API message for the Overseer. */
    +  public static void injectTraceContext(Map<String, Object> message) {
    +    if (Span.current().getSpanContext().isValid()) {
    +      getTextMapPropagator()
    +          .inject(Context.current(), message, (m, k, v) -> m.put(MESSAGE_TRACE_PREFIX + k, v));
    +    }
    +  }
    +
    +  /** Reads the trace context added by {@link #injectTraceContext(Map)}, if any. */
    +  public static Context extractTraceContext(ZkNodeProps message) {
    +    return getTextMapPropagator().extract(Context.current(), message, MESSAGE_GETTER);
    +  }
    +
    +  /** Returns the message without the keys added by {@link #injectTraceContext(Map)}. */
    +  public static ZkNodeProps removeTraceContext(ZkNodeProps message) {

    Thanks @dsmiley, you're right. Only MODIFYCOLLECTION and CREATEALIAS use every message key, and the handler already skips injecting for both, so I removed the strip.

    sarkaramrit1993 sarkaramrit1993 commented on code on Nov 30, 2026 10:29 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -172,11 +214,15 @@ public static void setOperations(SolrQueryRequest req, String clazz, List<String
       }
     
       public static Span startCollectionApiCommandSpan(
    -      String name, String collection, boolean isAsync) {
    +      String name, String collection, boolean isAsync, Context parent) {
         Tracer tracer = getGlobalTracer();
         SpanKind kind = isAsync ? SpanKind.PRODUCER : SpanKind.CLIENT;

    Thanks @dsmiley. With the Overseer disabled, the command runs under the caller's span, so this span is only started on the Overseer path. I kept the kind unchanged since this PR only changes the parent.

    sarkaramrit1993 sarkaramrit1993 commented on code on Nov 30, 2026 10:29 UTC
    Code Review
    solr/modules/opentelemetry/src/test-files/solr/tracing/TestDistributedTracing/testV2Api.json:1
    @@ -1,57 +1,56 @@
     {"phases":[
         {
           "description":"phase 0",
    -      "spans":[
    -        {
    -          "name":"ReloadCollectionCmd",
    -          "kind":"CLIENT",
    -          "db.instance":"collection1",
    -          "children":[
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard1_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"},
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard1_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"},
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard2_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"},
    -            {
    -              "name":"reload:/admin/cores",
    -              "kind":"SERVER",
    -              "db.instance":"collection1_shard2_replica_nN",
    -              "db.type":"solr",
    -              "http.request.method":"POST",
    -              "http.response.status_code":200,
    -              "http.url":"http://NORMALIZED/solr/admin/cores",
    -              "http.params":"action=RELOAD"}]},
    -        {
    +      "spans":[{

    Thanks @dsmiley. This is the verifier's regenerated output. ReloadCollectionCmd moved from its own root to a child of the request span, which re-indents that subtree. Hiding whitespace shows the 11-line change.

    dsmiley dsmiley commented on code on Nov 30, 2026 14:10 UTC
    Code Review
    solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:1
    @@ -172,11 +214,15 @@ public static void setOperations(SolrQueryRequest req, String clazz, List<String
       }
     
       public static Span startCollectionApiCommandSpan(
    -      String name, String collection, boolean isAsync) {
    +      String name, String collection, boolean isAsync, Context parent) {
         Tracer tracer = getGlobalTracer();
         SpanKind kind = isAsync ? SpanKind.PRODUCER : SpanKind.CLIENT;

    Your explanation helps justify my concern about TraceUtils. It's not apparent from the code here that what you said is true! If tracing was inlined into the call-sites, then a reader could deduce what you said much more easily.

    On the other hand, the method could be named with "Overseer" in it and then it'd assuage my concern. Let's do that.

    Reviewers
    Assignees
    sarkaramrit1993 sarkaramrit1993
    Labels
    risk: low confidence: 90.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 47.5% (MEDIUM) · Higher = larger blast radius
    47.5%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 90.1% · Lower = rushed or shallow review
    90.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 4.7% · Safe to merge
    4.7%
    Repository