-
Notifications
You must be signed in to change notification settings - Fork 6.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix RuntimeContext cannot store anything when the trace is not creat (#…
…1480) * Fix RuntimeContext cannot store anything when the trace is not create * Add RuntimecontextSnapshot and remove debug info
- Loading branch information
Showing
28 changed files
with
322 additions
and
107 deletions.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
.../src/main/java/org/apache/skywalking/apm/agent/core/conf/RuntimeContextConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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.agent.core.conf; | ||
|
||
public class RuntimeContextConfiguration { | ||
|
||
public static String[] NEED_PROPAGATE_CONTEXT_KEY = new String[] { | ||
"SW_REQUEST", | ||
"SW_RESPONSE" | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
...re/src/main/java/org/apache/skywalking/apm/agent/core/context/RuntimeContextSnapshot.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* 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.agent.core.context; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
|
||
public class RuntimeContextSnapshot { | ||
private final Map map; | ||
|
||
public RuntimeContextSnapshot(Map map) { | ||
this.map = map; | ||
} | ||
|
||
public Iterator<Map.Entry> iterator() { | ||
return map.entrySet().iterator(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
...va/org/apache/skywalking/apm/plugin/hystrix/v1/HystrixConcurrencyStrategyInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* 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.hystrix.v1; | ||
|
||
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; | ||
import java.lang.reflect.Method; | ||
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; | ||
|
||
public class HystrixConcurrencyStrategyInterceptor implements InstanceMethodsAroundInterceptor { | ||
@Override | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
MethodInterceptResult result) throws Throwable { | ||
|
||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, | ||
Object ret) throws Throwable { | ||
return new SWHystrixConcurrencyStrategyWrapper((HystrixConcurrencyStrategy)ret); | ||
} | ||
|
||
@Override public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, | ||
Class<?>[] argumentsTypes, Throwable t) { | ||
|
||
} | ||
} |
64 changes: 64 additions & 0 deletions
64
...java/org/apache/skywalking/apm/plugin/hystrix/v1/SWHystrixConcurrencyStrategyWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
/* | ||
* 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.hystrix.v1; | ||
|
||
import com.netflix.hystrix.strategy.concurrency.HystrixConcurrencyStrategy; | ||
import java.util.concurrent.Callable; | ||
import org.apache.skywalking.apm.agent.core.conf.RuntimeContextConfiguration; | ||
import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
import org.apache.skywalking.apm.agent.core.context.RuntimeContextSnapshot; | ||
|
||
public class SWHystrixConcurrencyStrategyWrapper extends HystrixConcurrencyStrategy { | ||
|
||
private final HystrixConcurrencyStrategy delegate; | ||
|
||
public SWHystrixConcurrencyStrategyWrapper( | ||
HystrixConcurrencyStrategy delegate) { | ||
this.delegate = delegate; | ||
} | ||
|
||
@Override | ||
public <T> Callable<T> wrapCallable(Callable<T> callable) { | ||
return new WrappedCallable<T>(ContextManager.getRuntimeContext().capture(), super.wrapCallable(callable)); | ||
} | ||
|
||
static class WrappedCallable<T> implements Callable<T> { | ||
|
||
private final RuntimeContextSnapshot contextSnapshot; | ||
private final Callable<T> target; | ||
|
||
WrappedCallable(RuntimeContextSnapshot contextSnapshot, Callable<T> target) { | ||
this.contextSnapshot = contextSnapshot; | ||
this.target = target; | ||
} | ||
|
||
@Override public T call() throws Exception { | ||
try { | ||
ContextManager.getRuntimeContext().accept(contextSnapshot); | ||
return target.call(); | ||
} finally { | ||
for (String key : RuntimeContextConfiguration.NEED_PROPAGATE_CONTEXT_KEY) { | ||
ContextManager.getRuntimeContext().remove(key); | ||
} | ||
} | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.