stillalex commented on code in PR #1854:
URL: https://github.com/apache/solr/pull/1854#discussion_r1299273700


##########
solr/modules/opentelemetry/src/java/org/apache/solr/opentelemetry/simplepropagator/SimplePropagator.java:
##########
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.solr.opentelemetry.simplepropagator;
+
+import io.opentelemetry.context.Context;
+import io.opentelemetry.context.ContextKey;
+import io.opentelemetry.context.propagation.TextMapGetter;
+import io.opentelemetry.context.propagation.TextMapPropagator;
+import io.opentelemetry.context.propagation.TextMapSetter;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+import java.util.concurrent.atomic.AtomicLong;
+import org.apache.solr.logging.MDCLoggingContext;
+
+/** Simple Http Header Propagator */
+public class SimplePropagator implements TextMapPropagator {
+
+  private static final TextMapPropagator INSTANCE = new SimplePropagator();
+  private static final ContextKey<String> TRACE_ID_KEY = 
ContextKey.named("trace_id");
+
+  private static final String TRACE_ID = System.getProperty("TRACE_ID", 
"X-Trace-Id");
+  private static final List<String> FIELDS = List.of(TRACE_ID);
+
+  private static final AtomicLong traceCounter = new AtomicLong(0);
+
+  public static TextMapPropagator getInstance() {
+    return INSTANCE;
+  }
+
+  private SimplePropagator() {}
+
+  @Override
+  public Collection<String> fields() {
+    return FIELDS;
+  }
+
+  @Override
+  public <C> void inject(Context context, C carrier, TextMapSetter<C> setter) {
+    if (setter == null) {
+      return;
+    }
+    String traceId = context.get(TRACE_ID_KEY);
+    if (traceId != null) {
+      setter.set(carrier, TRACE_ID, traceId);
+    }
+  }
+
+  @Override
+  public <C> Context extract(Context context, C carrier, TextMapGetter<C> 
getter) {
+    String traceId = getter.get(carrier, TRACE_ID);
+    if (traceId == null) {
+      traceId = newTraceId();
+    }
+
+    MDCLoggingContext.setTracerId(traceId);
+    return context.with(TRACE_ID_KEY, traceId);
+  }
+
+  private static String newTraceId() {
+    return String.format("%s-%d", UUID.randomUUID(), 
traceCounter.incrementAndGet());

Review Comment:
   ok. makes sense will keep the existing mechanism.



-- 
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: issues-unsubscr...@solr.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@solr.apache.org
For additional commands, e-mail: issues-h...@solr.apache.org

Reply via email to