sarkaramrit1993 commented on code in PR #5405:
URL: https://github.com/apache/solr/pull/5405#discussion_r4737841457
##########
solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:
##########
@@ -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. */
Review Comment:
Thanks @dsmiley, good point. I moved the message helpers into
`TraceAwareCommand`, next to where they're used, so `TraceUtils` only gains the
`parent` arg.
##########
solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:
##########
@@ -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) {
Review Comment:
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.
##########
solr/core/src/java/org/apache/solr/util/tracing/TraceUtils.java:
##########
@@ -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;
Review Comment:
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.
##########
solr/modules/opentelemetry/src/test-files/solr/tracing/TestDistributedTracing/testV2Api.json:
##########
@@ -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":[{
Review Comment:
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.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]