You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@skywalking.apache.org by GitBox <gi...@apache.org> on 2022/11/02 09:37:47 UTC

[GitHub] [skywalking-java] wuwen5 opened a new pull request, #371: Support mannual propagation of trace context to next stream for webflux.

wuwen5 opened a new pull request, #371:
URL: https://github.com/apache/skywalking-java/pull/371

   <!--
       ⚠️ Please make sure to read this template first, pull requests that don't accord with this template
       maybe closed without notice.
       Texts surrounded by `<` and `>` are meant to be replaced by you, e.g. <framework name>, <issue number>.
       Put an `x` in the `[ ]` to mark the item as CHECKED. `[x]`
   -->
   
   <!-- ==== πŸ› Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist πŸ‘‡ ====
   ### Fix <bug description or the bug issue number or bug issue link>
   - [ ] Add a unit test to verify that the fix works.
   - [ ] Explain briefly why the bug exists and how to fix it.
        ==== πŸ› Remove this line WHEN AND ONLY WHEN you're fixing a bug, follow the checklist πŸ‘† ==== -->
   
   <!-- ==== πŸ”Œ Remove this line WHEN AND ONLY WHEN you're adding a new plugin, follow the checklist πŸ‘‡ ====
   ### Add an agent plugin to support <framework name>
   - [ ] Add a test case for the new plugin, refer to [the doc](https://github.com/apache/skywalking-java/blob/main/docs/en/setup/service-agent/java-agent/Plugin-test.md)
   - [ ] Add a component id in [the component-libraries.yml](https://github.com/apache/skywalking/blob/master/oap-server/server-starter/src/main/resources/component-libraries.yml)
   - [ ] Add a logo in [the UI repo](https://github.com/apache/skywalking-rocketbot-ui/tree/master/src/views/components/topology/assets)
        ==== πŸ”Œ Remove this line WHEN AND ONLY WHEN you're adding a new plugin, follow the checklist πŸ‘† ==== -->
   
   <!-- ==== πŸ“ˆ Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist πŸ‘‡ ====
   ### Improve the performance of <class or module or ...>
   - [ ] Add a benchmark for the improvement, refer to [the existing ones](https://github.com/apache/skywalking-java/blob/main/apm-commons/apm-datacarrier/src/test/java/org/apache/skywalking/apm/commons/datacarrier/LinkedArrayBenchmark.java)
   - [ ] The benchmark result.
   ```text
   <Paste the benchmark results here>
   ```
   - [ ] Links/URLs to the theory proof or discussion articles/blogs. <links/URLs here>
        ==== πŸ“ˆ Remove this line WHEN AND ONLY WHEN you're improving the performance, follow the checklist πŸ‘† ==== -->
   
   <!-- ==== πŸ†• Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist πŸ‘‡ ====
   ### <Feature description>
   - [ ] If this is non-trivial feature, paste the links/URLs to the design doc.
   - [ ] Update the documentation to include this new feature.
   - [ ] Tests(including UT, IT, E2E) are added to verify the new feature.
   - [ ] If it's UI related, attach the screenshots below.
        ==== πŸ†• Remove this line WHEN AND ONLY WHEN you're adding a new feature, follow the checklist πŸ‘† ==== -->
   
   Currently, the webflux plug-in does not support tracking downstream component calls.
   
   e.g.
   ```java
   @GetMapping("/testcase/annotation/mono/onnext")
       public Mono<String> monoOnNext(@RequestBody(required = false) String body) {
           return Mono.subscriberContext()
                   .flatMap(ctx -> {
                       visit("http://localhost:" + serverPort + "/testcase/success");
                       //e.g. redis、dubbo and other components calls cannot be traced
                       return Mono.just("Hello World");
                   });
       }
   ```
   
   Related issue: https://github.com/apache/skywalking/issues/8644
   
   This implementation has learned from `spring-cloud-sleuth`'s manual mode
   
   - [ ] If this pull request closes/resolves/fixes an existing issue, replace the issue number. Closes #<issue number>.
   - [x] Update the [`CHANGES` log](https://github.com/apache/skywalking-java/blob/main/CHANGES.md).
   


-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #371: Support mannual propagation of tracing context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1011801596


##########
docs/menu.yml:
##########
@@ -46,6 +46,10 @@ catalog:
             path: "/en/setup/service-agent/java-agent/application-toolkit-trace-cross-thread"
           - name: "MicroMeter Registry"
             path: "/en/setup/service-agent/java-agent/application-toolkit-micrometer"
+          - name: "Webflux"
+            path: "/en/setup/service-agent/java-agent/application-toolkit-webflux"
+          - name: "Kafka"
+            path: "/en/setup/service-agent/java-agent/application-toolkit-kafka"  

Review Comment:
   ```suggestion
             - name: "Webflux Tracing Assistant APIs"
               path: "/en/setup/service-agent/java-agent/application-toolkit-webflux"
             - name: "Kafka Tracing Assistant APIs"
               path: "/en/setup/service-agent/java-agent/application-toolkit-kafka"  
   ```



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #371: Support mannual propagation of tracing context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1011689925


##########
apm-application-toolkit/apm-toolkit-webflux/src/main/java/org/apache/skywalking/apm/toolkit/webflux/WebFluxSkyWalkingOperators.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.skywalking.apm.toolkit.webflux;
+
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Signal;
+import reactor.core.publisher.SignalType;
+import reactor.util.context.Context;
+
+import java.util.concurrent.Callable;
+import java.util.function.Consumer;
+
+/**
+ * WebFlux operators that are capable to reuse tracing context from Reactor's Context.
+ */
+public final class WebFluxSkyWalkingOperators {
+
+    private WebFluxSkyWalkingOperators() {
+        throw new IllegalStateException("You can't instantiate a utility class");
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param signalType - Reactor's signal type
+     * @param runnable   - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal<?>> withSpanInScope(SignalType signalType, Runnable runnable) {
+        return signal -> {
+            if (signalType != signal.getType()) {
+                return;
+            }
+            withSpanInScope(runnable).accept(signal);
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param signalType - Reactor's signal type
+     * @param consumer   - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal> withSpanInScope(SignalType signalType, Consumer<Signal> consumer) {
+        return signal -> {
+            if (signalType != signal.getType()) {
+                return;
+            }
+            withSpanInScope(signal.getContext(), () -> consumer.accept(signal));
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param runnable - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal> withSpanInScope(Runnable runnable) {
+        return signal -> {
+            Context context = signal.getContext();
+            withSpanInScope(context, runnable);
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param context  - Reactor context that contains the tracing context
+     * @param runnable - lambda to execute within the tracing context
+     */
+    public static void withSpanInScope(Context context, Runnable runnable) {
+        runnable.run();
+    }
+
+    /**
+     * Wraps a callable with a span.
+     *
+     * @param context  - Reactor context that contains the tracing context
+     * @param callable - lambda to execute within the tracing context
+     * @param <T>      callable's return type
+     * @return value from the callable
+     */
+    public static <T> T withSpanInScope(Context context, Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        } 
+    }
+
+    public static <T> T withSpanInScope(ServerWebExchange serverWebExchange, Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);

Review Comment:
   I mean, you don't need to catch? As a wrapper, it should declare the same `throw` as the original.



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #371: Support mannual propagation of trace context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1011477344


##########
apm-application-toolkit/apm-toolkit-webflux/src/main/java/org/apache/skywalking/apm/toolkit/webflux/WebFluxSkyWalkingOperators.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.skywalking.apm.toolkit.webflux;
+
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Signal;
+import reactor.core.publisher.SignalType;
+import reactor.util.context.Context;
+
+import java.util.concurrent.Callable;
+import java.util.function.Consumer;
+
+/**
+ * WebFlux operators that are capable to reuse tracing context from Reactor's Context.
+ */
+public final class WebFluxSkyWalkingOperators {
+
+    private WebFluxSkyWalkingOperators() {
+        throw new IllegalStateException("You can't instantiate a utility class");
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param signalType - Reactor's signal type
+     * @param runnable   - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal<?>> withSpanInScope(SignalType signalType, Runnable runnable) {
+        return signal -> {
+            if (signalType != signal.getType()) {
+                return;
+            }
+            withSpanInScope(runnable).accept(signal);
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param signalType - Reactor's signal type
+     * @param consumer   - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal> withSpanInScope(SignalType signalType, Consumer<Signal> consumer) {
+        return signal -> {
+            if (signalType != signal.getType()) {
+                return;
+            }
+            withSpanInScope(signal.getContext(), () -> consumer.accept(signal));
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param runnable - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal> withSpanInScope(Runnable runnable) {
+        return signal -> {
+            Context context = signal.getContext();
+            withSpanInScope(context, runnable);
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param context  - Reactor context that contains the tracing context
+     * @param runnable - lambda to execute within the tracing context
+     */
+    public static void withSpanInScope(Context context, Runnable runnable) {
+        runnable.run();
+    }
+
+    /**
+     * Wraps a callable with a span.
+     *
+     * @param context  - Reactor context that contains the tracing context
+     * @param callable - lambda to execute within the tracing context
+     * @param <T>      callable's return type
+     * @return value from the callable
+     */
+    public static <T> T withSpanInScope(Context context, Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        } 
+    }
+
+    public static <T> T withSpanInScope(ServerWebExchange serverWebExchange, Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);

Review Comment:
   Why do we through an IllegalStateException from any caught exception? This seems wrong. 



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on pull request #371: Support mannual propagation of tracing context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#issuecomment-1301508356

   One new plugin is being added, please update plugin-list.md


-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on pull request #371: Support mannual propagation of trace context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#issuecomment-1299953839

   A doc should be added under `Manual APIs` menu. 
   
   Also, as you mentioned, I noticed Kafka API, which doesn't have a document too. Could you also add a doc for it (including a change log)? See the original PR https://github.com/apache/skywalking/pull/5304


-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #371: Support mannual propagation of trace context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1011474800


##########
apm-sniffer/apm-toolkit-activation/apm-toolkit-kafka-activation/src/main/resources/skywalking-plugin.def:
##########
@@ -14,4 +14,4 @@
 # See the License for the specific language governing permissions and
 # limitations under the License.
 
-toolkit-kafka=org.apache.skywalking.apm.toolkit.activation.kafka.define.KafkaOnMessageAnnotationInstrumentation
\ No newline at end of file
+toolkit-kafka=org.apache.skywalking.apm.toolkit.activation.webflux.WebFluxSkyWalkingOperatorsActivation

Review Comment:
   I think this should not be changed.



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng merged pull request #371: Support mannual propagation of tracing context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng merged PR #371:
URL: https://github.com/apache/skywalking-java/pull/371


-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on pull request #371: Support mannual propagation of trace context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#issuecomment-1299975108

   And please fix CI.


-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #371: Support mannual propagation of tracing context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1012444846


##########
test/plugin/scenarios/webflux-scenario/webflux-projectB-scenario/src/main/java/test/apache/skywalking/apm/testcase/sc/webflux/projectB/controller/TestAnnotationController.java:
##########
@@ -59,4 +66,18 @@ public Mono<String> urlPattern(@PathVariable("test") String var) {
     public Mono<String> hello(@RequestBody(required = false) String body) {
         return Mono.just("Hello World");
     }
+
+    @RequestMapping("/testcase/success")
+    public String downstreamMock() {
+        return "1";
+    }
+
+    @GetMapping("/testcase/annotation/mono/onnext")
+    public Mono<String> monoOnNext(@RequestBody(required = false) String body) {
+        return Mono.subscriberContext()
+                .flatMap(ctx -> WebFluxSkyWalkingOperators.withSpanInScope(ctx, () -> {

Review Comment:
   One question is `WebFluxSkyWalkingOperators#withSpanInScope` being called in the thread having to trace context, capture the snapshot, and continue this snapshot in the callback of another thread, right?
   
   If I got this scenario correctly, I would recommend this API be renamed to `WebFluxSkyWalkingOperators#continueTracing`.



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wu-sheng commented on a diff in pull request #371: Support mannual propagation of tracing context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wu-sheng commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1011802450


##########
CHANGES.md:
##########
@@ -24,13 +24,15 @@ Release Notes.
 * Polish up activemq plugin to fix missing broker tag on consumer side
 * Enhance MQ plugin relative tests to check key tags not blank.
 * Add RocketMQ test scenarios for version 4.3 - 4.9. No 4.0 - 4.2 release images for testing.
+* Support mannual propagation of tracing context to next operators for webflux.
 
 #### Documentation
 
 * Update `configuration` doc about overriding default value as empty map/list accordingly.
 * Update plugin dev tags for cache relative tags.
 * Add plugin dev docs for virtual database tags.
 * Add plugin dev docs for virtual MQ tags.
+* Add doc about kafka plugin Manual APIs.

Review Comment:
   ```suggestion
   * Add doc about kafka plugin Manual APIs.
   
   ```



-- 
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: notifications-unsubscribe@skywalking.apache.org

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


[GitHub] [skywalking-java] wuwen5 commented on a diff in pull request #371: Support mannual propagation of trace context to next stream for webflux.

Posted by GitBox <gi...@apache.org>.
wuwen5 commented on code in PR #371:
URL: https://github.com/apache/skywalking-java/pull/371#discussion_r1011686007


##########
apm-application-toolkit/apm-toolkit-webflux/src/main/java/org/apache/skywalking/apm/toolkit/webflux/WebFluxSkyWalkingOperators.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * 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.skywalking.apm.toolkit.webflux;
+
+import org.springframework.web.server.ServerWebExchange;
+import reactor.core.publisher.Signal;
+import reactor.core.publisher.SignalType;
+import reactor.util.context.Context;
+
+import java.util.concurrent.Callable;
+import java.util.function.Consumer;
+
+/**
+ * WebFlux operators that are capable to reuse tracing context from Reactor's Context.
+ */
+public final class WebFluxSkyWalkingOperators {
+
+    private WebFluxSkyWalkingOperators() {
+        throw new IllegalStateException("You can't instantiate a utility class");
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param signalType - Reactor's signal type
+     * @param runnable   - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal<?>> withSpanInScope(SignalType signalType, Runnable runnable) {
+        return signal -> {
+            if (signalType != signal.getType()) {
+                return;
+            }
+            withSpanInScope(runnable).accept(signal);
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param signalType - Reactor's signal type
+     * @param consumer   - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal> withSpanInScope(SignalType signalType, Consumer<Signal> consumer) {
+        return signal -> {
+            if (signalType != signal.getType()) {
+                return;
+            }
+            withSpanInScope(signal.getContext(), () -> consumer.accept(signal));
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param runnable - lambda to execute within the tracing context
+     * @return consumer of a signal
+     */
+    public static Consumer<Signal> withSpanInScope(Runnable runnable) {
+        return signal -> {
+            Context context = signal.getContext();
+            withSpanInScope(context, runnable);
+        };
+    }
+
+    /**
+     * Wraps a runnable with a span.
+     *
+     * @param context  - Reactor context that contains the tracing context
+     * @param runnable - lambda to execute within the tracing context
+     */
+    public static void withSpanInScope(Context context, Runnable runnable) {
+        runnable.run();
+    }
+
+    /**
+     * Wraps a callable with a span.
+     *
+     * @param context  - Reactor context that contains the tracing context
+     * @param callable - lambda to execute within the tracing context
+     * @param <T>      callable's return type
+     * @return value from the callable
+     */
+    public static <T> T withSpanInScope(Context context, Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);
+        } 
+    }
+
+    public static <T> T withSpanInScope(ServerWebExchange serverWebExchange, Callable<T> callable) {
+        try {
+            return callable.call();
+        } catch (Exception e) {
+            throw new IllegalStateException(e);

Review Comment:
   If throwing directly will cause trouble for the use of lambda, I have changed to the `sneakyThrow `



-- 
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: notifications-unsubscribe@skywalking.apache.org

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