-
Notifications
You must be signed in to change notification settings - Fork 6.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
1,257 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
~ 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. | ||
~ | ||
--> | ||
|
||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>apm-sdk-plugin</artifactId> | ||
<groupId>org.apache.skywalking</groupId> | ||
<version>6.5.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>apm-ehcache-2.x-plugin</artifactId> | ||
<name>ehcache-2.x-plugin</name> | ||
<packaging>jar</packaging> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<ehcache-client.version>2.10.2.2.21</ehcache-client.version> | ||
</properties> | ||
|
||
<dependencies> | ||
|
||
<dependency> | ||
<groupId>net.sf.ehcache</groupId> | ||
<artifactId>ehcache</artifactId> | ||
<version>${ehcache-client.version}</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
|
||
</dependencies> | ||
|
||
|
||
|
||
</project> |
38 changes: 38 additions & 0 deletions
38
.../main/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheConstructorInterceptor.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,38 @@ | ||
/* | ||
* 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.ehcache.v2; | ||
|
||
import net.sf.ehcache.config.CacheConfiguration; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.EnhancedInstance; | ||
import org.apache.skywalking.apm.agent.core.plugin.interceptor.enhance.InstanceConstructorInterceptor; | ||
|
||
/** | ||
* @author MrPro | ||
*/ | ||
public class EhcacheConstructorInterceptor implements InstanceConstructorInterceptor { | ||
@Override | ||
public void onConstruct(EnhancedInstance objInst, Object[] allArguments) { | ||
CacheConfiguration cacheConfiguration = (CacheConfiguration) allArguments[0]; | ||
|
||
// get cache name | ||
if (cacheConfiguration != null) { | ||
objInst.setSkyWalkingDynamicField(new EhcacheEnhanceInfo(cacheConfiguration.getName())); | ||
} | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...-plugin/src/main/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheEnhanceInfo.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,42 @@ | ||
/* | ||
* 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.ehcache.v2; | ||
|
||
/** | ||
* @author MrPro | ||
*/ | ||
public class EhcacheEnhanceInfo { | ||
|
||
private String cacheName; | ||
|
||
public EhcacheEnhanceInfo() { | ||
} | ||
|
||
public EhcacheEnhanceInfo(String cacheName) { | ||
this.cacheName = cacheName; | ||
} | ||
|
||
public String getCacheName() { | ||
return cacheName; | ||
} | ||
|
||
public void setCacheName(String cacheName) { | ||
this.cacheName = cacheName; | ||
} | ||
} |
65 changes: 65 additions & 0 deletions
65
...gin/src/main/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheLockInterceptor.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,65 @@ | ||
/* | ||
* 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.ehcache.v2; | ||
|
||
import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
import org.apache.skywalking.apm.agent.core.context.tag.Tags; | ||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; | ||
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; | ||
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 java.lang.reflect.Method; | ||
|
||
import static org.apache.skywalking.apm.plugin.ehcache.v2.define.EhcachePluginInstrumentation.LOCK_ENHANCE_METHOD_SUFFIX; | ||
|
||
/** | ||
* @author MrPro | ||
*/ | ||
public class EhcacheLockInterceptor implements InstanceMethodsAroundInterceptor { | ||
|
||
@Override | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { | ||
EhcacheEnhanceInfo enhanceInfo = (EhcacheEnhanceInfo) objInst.getSkyWalkingDynamicField(); | ||
|
||
String operateName = method.getName().substring(0, method.getName().length() - LOCK_ENHANCE_METHOD_SUFFIX.length()); | ||
|
||
AbstractSpan span = ContextManager.createLocalSpan("Ehcache/" + operateName + "/" + enhanceInfo.getCacheName()); | ||
span.setComponent(ComponentsDefine.EHCACHE); | ||
SpanLayer.asCache(span); | ||
|
||
Object element = allArguments[0]; | ||
if (element != null) { | ||
Tags.DB_STATEMENT.set(span, element.toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { | ||
ContextManager.stopSpan(); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { | ||
ContextManager.activeSpan().errorOccurred().log(t); | ||
} | ||
} |
55 changes: 55 additions & 0 deletions
55
...c/main/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheOperateAllInterceptor.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,55 @@ | ||
/* | ||
* 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.ehcache.v2; | ||
|
||
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.context.trace.SpanLayer; | ||
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 java.lang.reflect.Method; | ||
|
||
/** | ||
* @author MrPro | ||
*/ | ||
public class EhcacheOperateAllInterceptor implements InstanceMethodsAroundInterceptor { | ||
|
||
@Override | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { | ||
EhcacheEnhanceInfo enhanceInfo = (EhcacheEnhanceInfo) objInst.getSkyWalkingDynamicField(); | ||
|
||
AbstractSpan span = ContextManager.createLocalSpan("Ehcache/" + method.getName() + "/" + enhanceInfo.getCacheName()); | ||
span.setComponent(ComponentsDefine.EHCACHE); | ||
SpanLayer.asCache(span); | ||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { | ||
ContextManager.stopSpan(); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { | ||
ContextManager.activeSpan().errorOccurred().log(t); | ||
} | ||
} |
62 changes: 62 additions & 0 deletions
62
...in/java/org/apache/skywalking/apm/plugin/ehcache/v2/EhcacheOperateElementInterceptor.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,62 @@ | ||
/* | ||
* 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.ehcache.v2; | ||
|
||
import net.sf.ehcache.Element; | ||
import org.apache.skywalking.apm.agent.core.context.ContextManager; | ||
import org.apache.skywalking.apm.agent.core.context.tag.Tags; | ||
import org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan; | ||
import org.apache.skywalking.apm.agent.core.context.trace.SpanLayer; | ||
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 java.lang.reflect.Method; | ||
|
||
/** | ||
* @author MrPro | ||
*/ | ||
public class EhcacheOperateElementInterceptor implements InstanceMethodsAroundInterceptor { | ||
|
||
@Override | ||
public void beforeMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, MethodInterceptResult result) throws Throwable { | ||
EhcacheEnhanceInfo enhanceInfo = (EhcacheEnhanceInfo) objInst.getSkyWalkingDynamicField(); | ||
|
||
AbstractSpan span = ContextManager.createLocalSpan("Ehcache/" + method.getName() + "/" + enhanceInfo.getCacheName()); | ||
span.setComponent(ComponentsDefine.EHCACHE); | ||
SpanLayer.asCache(span); | ||
|
||
Element element = (Element) allArguments[0]; | ||
if (element != null && element.getObjectKey() != null) { | ||
Tags.DB_STATEMENT.set(span, element.getObjectKey().toString()); | ||
} | ||
} | ||
|
||
@Override | ||
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable { | ||
ContextManager.stopSpan(); | ||
return ret; | ||
} | ||
|
||
@Override | ||
public void handleMethodException(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Throwable t) { | ||
ContextManager.activeSpan().errorOccurred().log(t); | ||
} | ||
} |
Oops, something went wrong.