diff --git a/zipkin-server/server-core/pom.xml b/zipkin-server/server-core/pom.xml
index 315695c31cf..02b3525b5a0 100644
--- a/zipkin-server/server-core/pom.xml
+++ b/zipkin-server/server-core/pom.xml
@@ -24,6 +24,11 @@
zipkin-receiver-plugin
${skywalking.version}
+
+ io.github.classgraph
+ classgraph
+ 4.8.162
+
\ No newline at end of file
diff --git a/zipkin-server/server-core/src/main/java/zipkin/server/core/CoreModuleProvider.java b/zipkin-server/server-core/src/main/java/zipkin/server/core/CoreModuleProvider.java
index 1a53d44e44a..7b41cf933f2 100644
--- a/zipkin-server/server-core/src/main/java/zipkin/server/core/CoreModuleProvider.java
+++ b/zipkin-server/server-core/src/main/java/zipkin/server/core/CoreModuleProvider.java
@@ -99,14 +99,14 @@ public class CoreModuleProvider extends ModuleProvider {
private EndpointNameGrouping endpointNameGrouping;
private final ZipkinSourceReceiverImpl receiver;
- private final AnnotationScan annotationScan;
+ private final ZipkinAnnotationScan annotationScan;
private final StorageModels storageModels;
private RemoteClientManager remoteClientManager;
private GRPCServer grpcServer;
private HTTPServer httpServer;
public CoreModuleProvider() {
- this.annotationScan = new AnnotationScan();
+ this.annotationScan = new ZipkinAnnotationScan();
this.receiver = new ZipkinSourceReceiverImpl();
this.storageModels = new StorageModels();
}
@@ -147,16 +147,9 @@ public void prepare() throws ServiceNotProvidedException, ModuleStartException {
);
this.registerServiceImplementation(NamingControl.class, namingControl);
+ annotationScan.registerListener(new DefaultScopeDefine.Listener());
annotationScan.registerListener(new ZipkinStreamAnnotationListener(getManager()));
- AnnotationScan scopeScan = new AnnotationScan();
- scopeScan.registerListener(new DefaultScopeDefine.Listener());
- try {
- scopeScan.scan();
- } catch (Exception e) {
- throw new ModuleStartException(e.getMessage(), e);
- }
-
HTTPServerConfig httpServerConfig = HTTPServerConfig.builder()
.host(moduleConfig.getRestHost())
.port(moduleConfig.getRestPort())
diff --git a/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinAnnotationScan.java b/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinAnnotationScan.java
new file mode 100644
index 00000000000..02c45b84d3d
--- /dev/null
+++ b/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinAnnotationScan.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright 2015-2023 The OpenZipkin Authors
+ *
+ * Licensed 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 zipkin.server.core;
+
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
+import org.apache.skywalking.oap.server.core.annotation.AnnotationListener;
+import org.apache.skywalking.oap.server.core.storage.StorageException;
+
+import java.io.IOException;
+import java.lang.annotation.Annotation;
+import java.util.Comparator;
+import java.util.LinkedList;
+import java.util.List;
+
+public class ZipkinAnnotationScan {
+ private final List listeners;
+
+ public ZipkinAnnotationScan() {
+ this.listeners = new LinkedList<>();
+ }
+
+ /**
+ * Register the callback listener
+ *
+ * @param listener to be called after class found w/ annotation
+ */
+ public void registerListener(AnnotationListener listener) {
+ listeners.add(new AnnotationListenerCache(listener));
+ }
+
+ public void scan() throws IOException, StorageException {
+ ClassGraph classGraph = new ClassGraph();
+ classGraph.enableClassInfo();
+ final ScanResult scan = classGraph.scan();
+ for (ClassInfo classInfo : scan.getAllClasses()) {
+ // not skywalking package or a subclass should ignore
+ if (!classInfo.getName().startsWith("org.apache.skywalking") || classInfo.getName().contains("$")) {
+ continue;
+ }
+ final Class> aClass = classInfo.loadClass();
+ for (AnnotationListenerCache listener : listeners) {
+ if (aClass.isAnnotationPresent(listener.annotation())) {
+ listener.addMatch(aClass);
+ }
+ }
+ }
+
+ for (AnnotationListenerCache listener : listeners) {
+ listener.complete();
+ }
+ }
+
+ private class AnnotationListenerCache {
+ private AnnotationListener listener;
+ private List> matchedClass;
+
+ private AnnotationListenerCache(AnnotationListener listener) {
+ this.listener = listener;
+ matchedClass = new LinkedList<>();
+ }
+
+ private Class extends Annotation> annotation() {
+ return this.listener.annotation();
+ }
+
+ private void addMatch(Class aClass) {
+ matchedClass.add(aClass);
+ }
+
+ private void complete() throws StorageException {
+ matchedClass.sort(Comparator.comparing(Class::getName));
+ for (Class> aClass : matchedClass) {
+ listener.notify(aClass);
+ }
+ }
+ }
+
+}
diff --git a/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinDispatcherManager.java b/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinDispatcherManager.java
index c4c33d79d2e..81579eb44a1 100644
--- a/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinDispatcherManager.java
+++ b/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinDispatcherManager.java
@@ -14,11 +14,31 @@
package zipkin.server.core;
+import io.github.classgraph.ClassGraph;
+import io.github.classgraph.ClassInfo;
+import io.github.classgraph.ScanResult;
import org.apache.skywalking.oap.server.core.analysis.DispatcherManager;
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagAutocompleteDispatcher;
+import java.io.IOException;
+
public class ZipkinDispatcherManager extends DispatcherManager {
+ @Override
+ public void scan() throws IOException, IllegalAccessException, InstantiationException {
+ ClassGraph classGraph = new ClassGraph();
+ classGraph.enableClassInfo();
+ final ScanResult scan = classGraph.scan();
+ for (ClassInfo classInfo : scan.getAllClasses()) {
+ // not skywalking package or a subclass should ignore
+ if (!classInfo.getName().startsWith("org.apache.skywalking") || classInfo.getName().contains("$")) {
+ continue;
+ }
+ final Class> aClass = classInfo.loadClass();
+ addIfAsSourceDispatcher(aClass);
+ }
+ }
+
@Override
public void addIfAsSourceDispatcher(Class aClass) throws IllegalAccessException, InstantiationException {
if (aClass.getSimpleName().startsWith("Zipkin") || aClass.equals(TagAutocompleteDispatcher.class)) {
diff --git a/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinStreamAnnotationListener.java b/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinStreamAnnotationListener.java
index a1ba4398eb6..1d605b67b80 100644
--- a/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinStreamAnnotationListener.java
+++ b/zipkin-server/server-core/src/main/java/zipkin/server/core/ZipkinStreamAnnotationListener.java
@@ -16,6 +16,7 @@
import org.apache.skywalking.oap.server.core.analysis.StreamAnnotationListener;
import org.apache.skywalking.oap.server.core.analysis.manual.searchtag.TagAutocompleteData;
+import org.apache.skywalking.oap.server.core.analysis.manual.spanattach.SpanAttachedEventRecord;
import org.apache.skywalking.oap.server.core.storage.StorageException;
import org.apache.skywalking.oap.server.library.module.ModuleDefineHolder;
@@ -28,7 +29,7 @@ public ZipkinStreamAnnotationListener(ModuleDefineHolder moduleDefineHolder) {
@Override
public void notify(Class aClass) throws StorageException {
// only including all zipkin streaming
- if (aClass.getSimpleName().startsWith("Zipkin") || aClass.equals(TagAutocompleteData.class)) {
+ if (aClass.getSimpleName().startsWith("Zipkin") || aClass.equals(TagAutocompleteData.class) || aClass.equals(SpanAttachedEventRecord.class)) {
super.notify(aClass);
}
}