dsmiley commented on code in PR #5405:
URL: https://github.com/apache/solr/pull/5405#discussion_r4728411387
##########
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:
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.
##########
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:
is it really so bad to leave the trace context there?
##########
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:
hmm; the indentation style is different, which isn't good for diff'ing
##########
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:
I suppose SpanKind.CLIENT would only make sense for Overseer processing, but
not for disabled Overseer
--
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]