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 2019/11/15 12:42:50 UTC

[GitHub] [skywalking] kezhenxu94 commented on a change in pull request #3857: Support spring-tx in optional plugin

kezhenxu94 commented on a change in pull request #3857: Support spring-tx in optional plugin
URL: https://github.com/apache/skywalking/pull/3857#discussion_r346804103
 
 

 ##########
 File path: apm-sniffer/optional-plugins/optional-spring-plugins/spring-tx-plugin/src/main/java/org/apache/skywalking/apm/plugin/spring/transaction/GetTransactionMethodInterceptor.java
 ##########
 @@ -0,0 +1,76 @@
+/*
+ * 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.plugin.spring.transaction;
+
+import org.apache.skywalking.apm.agent.core.conf.Config;
+import org.apache.skywalking.apm.agent.core.context.ContextManager;
+import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceMethodsAroundInterceptor;
+import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.MethodInterceptResult;
+import org.apache.skywalking.apm.network.trace.component.ComponentsDefine;
+import org.apache.skywalking.apm.plugin.spring.transaction.context.Constants;
+import org.springframework.transaction.TransactionDefinition;
+
+import java.lang.reflect.Method;
+
+/**
+ * @author zhaoyuguang
+ */
+public class GetTransactionMethodInterceptor implements InstanceMethodsAroundInterceptor {
+    @Override
+    public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes,
+                             MethodInterceptResult result) throws Throwable {
+        TransactionDefinition definition = (TransactionDefinition) allArguments[0];
 
 Review comment:
   According to the [Spring source codes](https://github.com/spring-projects/spring-framework/blob/85471d05871ee8461b5f196ed26ffeb866d76cb2/spring-tx/src/main/java/org/springframework/transaction/support/AbstractPlatformTransactionManager.java#L341-L350), the `definition` is marked as `@Nullable`, and it may be null, so I'm wondering that have you covered this scenario? or should we consider this case? future users may encounter weird issues that are hard to diagnose when this happen
   
   ```java
   	public final TransactionStatus getTransaction(@Nullable TransactionDefinition definition) throws TransactionException {
   		Object transaction = doGetTransaction();
   
   
   		// Cache debug flag to avoid repeated checks.
   		boolean debugEnabled = logger.isDebugEnabled();
   
   
   		if (definition == null) {
   			// Use defaults if no transaction definition given.
   			definition = new DefaultTransactionDefinition();
   		}
   ```

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services