mirror of
https://github.com/wahyd4/pinpoint.git
synced 2026-08-16 08:16:15 +10:00
Merge pull request #963 from lioolli/master
Make jetty plugin use new plugin api
This commit is contained in:
+53
@@ -0,0 +1,53 @@
|
||||
/**
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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 com.navercorp.pinpoint.bootstrap.plugin.transformer;
|
||||
|
||||
import java.security.ProtectionDomain;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentClass;
|
||||
import com.navercorp.pinpoint.bootstrap.instrument.InstrumentException;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginInstrumentContext;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
*
|
||||
*/
|
||||
public class PinpointClassFileTransformers {
|
||||
|
||||
public static PinpointClassFileTransformer addInterceptor(final String interceptorClassName, final Object... constructorArgs) {
|
||||
return new PinpointClassFileTransformer() {
|
||||
|
||||
@Override
|
||||
public byte[] transform(ProfilerPluginInstrumentContext instrumentContext, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
|
||||
target.addInterceptor(interceptorClassName, constructorArgs);
|
||||
return target.toBytecode();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
public static PinpointClassFileTransformer addField(final String fieldAccessorClassName) {
|
||||
return new PinpointClassFileTransformer() {
|
||||
|
||||
@Override
|
||||
public byte[] transform(ProfilerPluginInstrumentContext instrumentContext, ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws InstrumentException {
|
||||
InstrumentClass target = instrumentContext.getInstrumentClass(loader, className, classfileBuffer);
|
||||
target.addField(fieldAccessorClassName);
|
||||
return target.toBytecode();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -243,6 +243,12 @@ public class ServiceType {
|
||||
public static final ServiceType STAND_ALONE = of(1000, "STAND_ALONE", NORMAL_SCHEMA, RECORD_STATISTICS);
|
||||
public static final ServiceType TEST_STAND_ALONE = of(1005, "TEST_STAND_ALONE", NORMAL_SCHEMA, RECORD_STATISTICS);
|
||||
|
||||
// TOMCAT 1010
|
||||
// TOMCAT_METHOD 1011
|
||||
|
||||
// JETTY 1020
|
||||
// JETTY_METHOD 1021
|
||||
|
||||
/**
|
||||
* Database shown only as xxx_EXECUTE_QUERY at the statistics info section in the server map
|
||||
*/
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ public class JettyConfiguration {
|
||||
|
||||
if (!jettyExcludeURL.isEmpty()) {
|
||||
this.jettyExcludeUrlFilter = new ExcludeUrlFilter(jettyExcludeURL);
|
||||
}
|
||||
else{
|
||||
} else{
|
||||
this.jettyExcludeUrlFilter = new SkipFilter<String>();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,9 +21,9 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
|
||||
public interface JettyConstants {
|
||||
public static final String TYPE_NAME = "JETTY";
|
||||
/*following two need fixing*/
|
||||
public static final ServiceType JETTY = ServiceType.of(1110, "JETTY", NORMAL_SCHEMA, RECORD_STATISTICS);
|
||||
public static final ServiceType JETTY_METHOD = ServiceType.of(1111, "JETTY_METHOD", NORMAL_SCHEMA);
|
||||
|
||||
public static final ServiceType JETTY = ServiceType.of(1020, "JETTY", NORMAL_SCHEMA, RECORD_STATISTICS);
|
||||
public static final ServiceType JETTY_METHOD = ServiceType.of(1021, "JETTY_METHOD", NORMAL_SCHEMA);
|
||||
|
||||
public static final String METADATA_TRACE = "trace";
|
||||
public static final String METADATA_ASYNC = "async";
|
||||
|
||||
@@ -22,7 +22,6 @@ public class JettyDetector implements ApplicationTypeDetector, JettyConstants {
|
||||
|
||||
private static final String REQUIRED_MAIN_CLASS = "org.eclipse.jetty.start.Main";
|
||||
|
||||
|
||||
@Override
|
||||
public ServiceType getApplicationType() {
|
||||
return JETTY;
|
||||
|
||||
@@ -16,7 +16,7 @@ package com.navercorp.pinpoint.plugin.jetty;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPlugin;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.ProfilerPluginSetupContext;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.transformer.ClassFileTransformerBuilder;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.transformer.PinpointClassFileTransformers;
|
||||
|
||||
public class JettyPlugin implements ProfilerPlugin, JettyConstants{
|
||||
|
||||
@@ -24,19 +24,16 @@ public class JettyPlugin implements ProfilerPlugin, JettyConstants{
|
||||
public void setup(ProfilerPluginSetupContext context) {
|
||||
context.addApplicationTypeDetector(new JettyDetector());
|
||||
JettyConfiguration config = new JettyConfiguration(context.getConfig());
|
||||
|
||||
addServerInterceptor(context, config);
|
||||
addRequestEditor(context);
|
||||
}
|
||||
|
||||
private void addServerInterceptor(ProfilerPluginSetupContext context, JettyConfiguration config){
|
||||
ClassFileTransformerBuilder builder = context.getClassFileTransformerBuilder("org.eclipse.jetty.server.Server");
|
||||
builder.injectInterceptor("com.navercorp.pinpoint.plugin.jetty.interceptor.ServerHandleInterceptor", config.getJettyExcludeUrlFilter());
|
||||
context.addClassFileTransformer(builder.build());
|
||||
context.addClassFileTransformer("org.eclipse.jetty.server.Server", PinpointClassFileTransformers.addInterceptor("com.navercorp.pinpoint.plugin.jetty.interceptor.ServerHandleInterceptor", config.getJettyExcludeUrlFilter()));
|
||||
}
|
||||
|
||||
private void addRequestEditor(ProfilerPluginSetupContext context) {
|
||||
ClassFileTransformerBuilder builder = context.getClassFileTransformerBuilder("org.eclipse.jetty.server.Request");
|
||||
builder.injectMetadata(METADATA_TRACE);
|
||||
context.addClassFileTransformer(builder.build());
|
||||
context.addClassFileTransformer("org.eclipse.jetty.server.Request", PinpointClassFileTransformers.addField("com.navercorp.pinpoint.plugin.jetty.interceptor.TraceAccessor"));
|
||||
}
|
||||
}
|
||||
|
||||
+5
-10
@@ -16,9 +16,9 @@ package com.navercorp.pinpoint.plugin.jetty.interceptor;
|
||||
|
||||
import java.util.Enumeration;
|
||||
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.MetadataAccessor;
|
||||
import com.navercorp.pinpoint.bootstrap.config.Filter;
|
||||
import com.navercorp.pinpoint.bootstrap.context.Header;
|
||||
import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder;
|
||||
@@ -31,7 +31,6 @@ import com.navercorp.pinpoint.bootstrap.interceptor.MethodDescriptor;
|
||||
import com.navercorp.pinpoint.bootstrap.interceptor.SimpleAroundInterceptor;
|
||||
import com.navercorp.pinpoint.bootstrap.logging.PLogger;
|
||||
import com.navercorp.pinpoint.bootstrap.logging.PLoggerFactory;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.annotation.Name;
|
||||
import com.navercorp.pinpoint.bootstrap.plugin.annotation.TargetMethod;
|
||||
import com.navercorp.pinpoint.bootstrap.sampler.SamplingFlagUtils;
|
||||
import com.navercorp.pinpoint.bootstrap.util.NetworkUtils;
|
||||
@@ -42,10 +41,8 @@ import com.navercorp.pinpoint.common.trace.ServiceType;
|
||||
import com.navercorp.pinpoint.plugin.jetty.JettyConstants;
|
||||
import com.navercorp.pinpoint.plugin.jetty.JettySyncMethodDescriptor;
|
||||
|
||||
import org.eclipse.jetty.server.HttpChannel;
|
||||
|
||||
@TargetMethod(name = "handle", paramTypes = { "org.eclipse.jetty.server.HttpChannel" })
|
||||
public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyConstants{
|
||||
public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyConstants {
|
||||
|
||||
public static final JettySyncMethodDescriptor JETTY_SYNC_API_TAG = new JettySyncMethodDescriptor();
|
||||
|
||||
@@ -56,14 +53,12 @@ public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyCo
|
||||
private final MethodDescriptor methodDescriptor;
|
||||
private final TraceContext traceContext;
|
||||
private final Filter<String> excludeUrlFilter;
|
||||
private final MetadataAccessor traceAccessor;
|
||||
|
||||
public ServerHandleInterceptor(TraceContext traceContext, MethodDescriptor descriptor, Filter<String> excludeFilter, @Name(METADATA_TRACE) MetadataAccessor traceAccessor) {
|
||||
public ServerHandleInterceptor(TraceContext traceContext, MethodDescriptor descriptor, Filter<String> excludeFilter) {
|
||||
|
||||
this.traceContext = traceContext;
|
||||
this.methodDescriptor = descriptor;
|
||||
this.excludeUrlFilter = excludeFilter;
|
||||
this.traceAccessor = traceAccessor;
|
||||
|
||||
traceContext.cacheApi(JETTY_SYNC_API_TAG);
|
||||
}
|
||||
@@ -198,8 +193,8 @@ public class ServerHandleInterceptor implements SimpleAroundInterceptor, JettyCo
|
||||
}
|
||||
|
||||
private void setTraceMetadata(final Request request, final Trace trace) {
|
||||
if(traceAccessor.isApplicable(request)) {
|
||||
traceAccessor.set(request, trace);
|
||||
if (request instanceof TraceAccessor) {
|
||||
((TraceAccessor)request)._$PINPOINT$_setTrace(trace);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
/**
|
||||
* Copyright 2014 NAVER Corp.
|
||||
* Licensed 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 com.navercorp.pinpoint.plugin.jetty.interceptor;
|
||||
|
||||
import com.navercorp.pinpoint.bootstrap.context.Trace;
|
||||
|
||||
/**
|
||||
* @author Jongho Moon
|
||||
*
|
||||
*/
|
||||
public interface TraceAccessor {
|
||||
public void _$PINPOINT$_setTrace(Trace trace);
|
||||
public Trace _$PINPOINT$_getTrace();
|
||||
}
|
||||
Reference in New Issue
Block a user