This is an automated email from the ASF dual-hosted git repository.

wusheng pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/skywalking.git


The following commit(s) were added to refs/heads/master by this push:
     new 43d79d9fec refactor: implement OTEL handler with SPI for extensibility 
(#13311)
43d79d9fec is described below

commit 43d79d9fec224036cc3cbc7185c9faa7ecd4838c
Author: kezhenxu94 <kezhenx...@apache.org>
AuthorDate: Sun Jun 15 19:06:57 2025 +0800

    refactor: implement OTEL handler with SPI for extensibility (#13311)
---
 docs/en/changes/changes.md                         |  1 +
 .../oap/server/receiver/otel/Handler.java          |  3 +++
 .../receiver/otel/OtelMetricReceiverProvider.java  | 22 +++++++---------------
 .../otel/otlp/OpenTelemetryLogHandler.java         |  8 +++++++-
 .../otel/otlp/OpenTelemetryMetricHandler.java      | 16 ++++++++++++----
 .../otel/otlp/OpenTelemetryTraceHandler.java       | 10 +++++++---
 ...che.skywalking.oap.server.receiver.otel.Handler | 21 +++++++++++++++++++++
 7 files changed, 58 insertions(+), 23 deletions(-)

diff --git a/docs/en/changes/changes.md b/docs/en/changes/changes.md
index ed1b2ed60b..6d53e69b08 100644
--- a/docs/en/changes/changes.md
+++ b/docs/en/changes/changes.md
@@ -42,6 +42,7 @@
 * Implement the Status API on Settings page.
 * Bump vite from 6.2.6 to 6.3.4.
 * Enhance async profiling by adding shorter and custom duration options.
+* refactor: implement OTEL handler with SPI for extensibility.
 
 #### Documentation
 
diff --git 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/Handler.java
 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/Handler.java
index 0a9b96abf5..a631af4fcc 100644
--- 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/Handler.java
+++ 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/Handler.java
@@ -18,9 +18,12 @@
 
 package org.apache.skywalking.oap.server.receiver.otel;
 
+import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.module.ModuleStartException;
 
 public interface Handler {
+    void init(ModuleManager manager, OtelMetricReceiverConfig config);
+
     String type();
 
     void active() throws ModuleStartException;
diff --git 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/OtelMetricReceiverProvider.java
 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/OtelMetricReceiverProvider.java
index 0cf91ca315..30e86556de 100644
--- 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/OtelMetricReceiverProvider.java
+++ 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/OtelMetricReceiverProvider.java
@@ -22,14 +22,12 @@ import 
org.apache.skywalking.oap.server.library.module.ModuleDefine;
 import org.apache.skywalking.oap.server.library.module.ModuleProvider;
 import org.apache.skywalking.oap.server.library.module.ModuleStartException;
 import 
org.apache.skywalking.oap.server.library.module.ServiceNotProvidedException;
-import 
org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryLogHandler;
-import 
org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryMetricHandler;
 import 
org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryMetricRequestProcessor;
-import 
org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryTraceHandler;
 import 
org.apache.skywalking.oap.server.receiver.sharing.server.SharingServerModule;
 
 import java.util.ArrayList;
 import java.util.List;
+import java.util.ServiceLoader;
 
 public class OtelMetricReceiverProvider extends ModuleProvider {
     public static final String NAME = "default";
@@ -71,19 +69,12 @@ public class OtelMetricReceiverProvider extends 
ModuleProvider {
             getManager(), config);
         
registerServiceImplementation(OpenTelemetryMetricRequestProcessor.class, 
metricRequestProcessor);
         final List<String> enabledHandlers = config.getEnabledHandlers();
-        List<Handler> handlers = new ArrayList<>();
 
-        final var openTelemetryMetricHandler = new 
OpenTelemetryMetricHandler(getManager(), metricRequestProcessor);
-        if (enabledHandlers.contains(openTelemetryMetricHandler.type())) {
-            handlers.add(openTelemetryMetricHandler);
-        }
-        final var openTelemetryLogHandler = new 
OpenTelemetryLogHandler(getManager());
-        if (enabledHandlers.contains(openTelemetryLogHandler.type())) {
-            handlers.add(openTelemetryLogHandler);
-        }
-        final var openTelemetryTraceHandler = new 
OpenTelemetryTraceHandler(getManager());
-        if (enabledHandlers.contains(openTelemetryTraceHandler.type())) {
-            handlers.add(openTelemetryTraceHandler);
+        final var handlers = new ArrayList<Handler>();
+        for (final var handler: ServiceLoader.load(Handler.class)) {
+            if (enabledHandlers.contains(handler.type())) {
+                handlers.add(handler);
+            }
         }
         this.handlers = handlers;
     }
@@ -92,6 +83,7 @@ public class OtelMetricReceiverProvider extends 
ModuleProvider {
     public void start() throws ServiceNotProvidedException, 
ModuleStartException {
         metricRequestProcessor.start();
         for (Handler h : handlers) {
+            h.init(getManager(), config);
             h.active();
         }
     }
diff --git 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryLogHandler.java
 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryLogHandler.java
index 35c75b7ace..a98839445c 100644
--- 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryLogHandler.java
+++ 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryLogHandler.java
@@ -39,6 +39,7 @@ import 
org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.module.ModuleStartException;
 import org.apache.skywalking.oap.server.receiver.otel.Handler;
+import org.apache.skywalking.oap.server.receiver.otel.OtelMetricReceiverConfig;
 import 
org.apache.skywalking.oap.server.receiver.sharing.server.SharingServerModule;
 import org.apache.skywalking.oap.server.telemetry.TelemetryModule;
 import org.apache.skywalking.oap.server.telemetry.api.HistogramMetrics;
@@ -55,7 +56,7 @@ import static java.util.stream.Collectors.toMap;
 public class OpenTelemetryLogHandler
     extends LogsServiceGrpc.LogsServiceImplBase
     implements Handler {
-    private final ModuleManager manager;
+    private ModuleManager manager;
 
     private ILogAnalyzerService logAnalyzerService;
 
@@ -70,6 +71,11 @@ public class OpenTelemetryLogHandler
         MetricsTag.EMPTY_VALUE
     );
 
+    @Override
+    public void init(ModuleManager manager, OtelMetricReceiverConfig config) {
+        this.manager = manager;
+    }
+
     @Override
     public String type() {
         return "otlp-logs";
diff --git 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
index edc7941221..5c69711ee6 100644
--- 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
+++ 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryMetricHandler.java
@@ -22,22 +22,30 @@ import io.grpc.stub.StreamObserver;
 import io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceRequest;
 import 
io.opentelemetry.proto.collector.metrics.v1.ExportMetricsServiceResponse;
 import io.opentelemetry.proto.collector.metrics.v1.MetricsServiceGrpc;
-import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.module.ModuleStartException;
 import org.apache.skywalking.oap.server.receiver.otel.Handler;
+import org.apache.skywalking.oap.server.receiver.otel.OtelMetricReceiverConfig;
+import org.apache.skywalking.oap.server.receiver.otel.OtelMetricReceiverModule;
 import 
org.apache.skywalking.oap.server.receiver.sharing.server.SharingServerModule;
 
 @Slf4j
-@RequiredArgsConstructor
 public class OpenTelemetryMetricHandler
     extends MetricsServiceGrpc.MetricsServiceImplBase
     implements Handler {
-    private final ModuleManager manager;
 
-    private final OpenTelemetryMetricRequestProcessor metricRequestProcessor;
+    private OpenTelemetryMetricRequestProcessor metricRequestProcessor;
+    private ModuleManager manager;
+
+    @Override
+    public void init(ModuleManager manager, OtelMetricReceiverConfig config) {
+        this.manager = manager;
+        metricRequestProcessor = manager.find(OtelMetricReceiverModule.NAME)
+                                        .provider()
+                                        
.getService(OpenTelemetryMetricRequestProcessor.class);
+    }
 
     @Override
     public String type() {
diff --git 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryTraceHandler.java
 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryTraceHandler.java
index f1b687ba50..73377286d6 100644
--- 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryTraceHandler.java
+++ 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/java/org/apache/skywalking/oap/server/receiver/otel/otlp/OpenTelemetryTraceHandler.java
@@ -31,13 +31,13 @@ import io.opentelemetry.proto.resource.v1.Resource;
 import io.opentelemetry.proto.trace.v1.ScopeSpans;
 import io.opentelemetry.proto.trace.v1.Status;
 import lombok.Getter;
-import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.apache.skywalking.oap.server.core.server.GRPCHandlerRegister;
 import org.apache.skywalking.oap.server.library.module.ModuleManager;
 import org.apache.skywalking.oap.server.library.module.ModuleStartException;
 import org.apache.skywalking.oap.server.library.util.StringUtil;
 import org.apache.skywalking.oap.server.receiver.otel.Handler;
+import org.apache.skywalking.oap.server.receiver.otel.OtelMetricReceiverConfig;
 import 
org.apache.skywalking.oap.server.receiver.sharing.server.SharingServerModule;
 import org.apache.skywalking.oap.server.receiver.zipkin.SpanForwardService;
 import org.apache.skywalking.oap.server.receiver.zipkin.ZipkinReceiverModule;
@@ -62,11 +62,10 @@ import java.util.concurrent.TimeUnit;
 import java.util.stream.Collectors;
 
 @Slf4j
-@RequiredArgsConstructor
 public class OpenTelemetryTraceHandler
     extends TraceServiceGrpc.TraceServiceImplBase
     implements Handler {
-    private final ModuleManager manager;
+    private ModuleManager manager;
     private SpanForwardService forwardService;
 
     @Getter(lazy = true)
@@ -80,6 +79,11 @@ public class OpenTelemetryTraceHandler
         MetricsTag.EMPTY_VALUE
     );
 
+    @Override
+    public void init(ModuleManager manager, OtelMetricReceiverConfig config) {
+        this.manager = manager;
+    }
+
     @Override
     public String type() {
         return "otlp-traces";
diff --git 
a/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.otel.Handler
 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.otel.Handler
new file mode 100644
index 0000000000..0f02db12c0
--- /dev/null
+++ 
b/oap-server/server-receiver-plugin/otel-receiver-plugin/src/main/resources/META-INF/services/org.apache.skywalking.oap.server.receiver.otel.Handler
@@ -0,0 +1,21 @@
+#
+# 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.
+#
+#
+
+org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryMetricHandler
+org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryLogHandler
+org.apache.skywalking.oap.server.receiver.otel.otlp.OpenTelemetryTraceHandler

Reply via email to