Skip to content

Commit

Permalink
[pinpoint-apm#3154] Add support for okhttp client 3.x
Browse files Browse the repository at this point in the history
  • Loading branch information
jaehong-kim committed Jul 13, 2017
1 parent f398b30 commit 80d0866
Show file tree
Hide file tree
Showing 35 changed files with 937 additions and 217 deletions.
5 changes: 2 additions & 3 deletions agent/src/main/resources-local/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -599,18 +599,17 @@ profiler.redis.io=true
###########################################################
# OkHttp
###########################################################
profiler.okhttp.enable=true
# Record param.
profiler.okhttp.param=true

# Record Cookies.
profiler.okhttp.cookie=false

# When to dump cookies. Either ALWAYS or EXCEPTION.
profiler.okhttp.cookie.dumptype=EXCEPTION

# 1 out of n cookies will be sampled where n is the rate. (1: 100%)
profiler.okhttp.cookie.sampling.rate=10

# enqueue operation
profiler.okhttp.async=true

###########################################################
Expand Down
5 changes: 2 additions & 3 deletions agent/src/main/resources-release/pinpoint.config
Original file line number Diff line number Diff line change
Expand Up @@ -592,18 +592,17 @@ profiler.redis.io=true
###########################################################
# OkHttp
###########################################################
profiler.okhttp.enable=true
# Record param.
profiler.okhttp.param=true

# Record Cookies.
profiler.okhttp.cookie=false

# When to dump cookies. Either ALWAYS or EXCEPTION.
profiler.okhttp.cookie.dumptype=EXCEPTION

# 1 out of n cookies will be sampled where n is the rate. (1: 100%)
profiler.okhttp.cookie.sampling.rate=10

# enqueue operation
profiler.okhttp.async=true

###########################################################
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,22 @@ profiler.google.httpclient.async=true
# Maximum anonymous innerclass number.
profiler.google.httpclient.async.innerclassname.max=3

###########################################################
# OkHttp
###########################################################
profiler.okhttp.enable=true
# Record param.
profiler.okhttp.param=true

# Record Cookies.
profiler.okhttp.cookie=false
# When to dump cookies. Either ALWAYS or EXCEPTION.
profiler.okhttp.cookie.dumptype=EXCEPTION
# 1 out of n cookies will be sampled where n is the rate. (1: 100%)
profiler.okhttp.cookie.sampling.rate=10
# enqueue operation
profiler.okhttp.async=true

###########################################################
# gson
###########################################################
Expand Down
6 changes: 6 additions & 0 deletions plugins/okhttp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,11 @@
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,4 @@ public static int getPort(int port, int defaultPort) {
}
return port;
}

}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,9 @@ private OkHttpConstants() {
public static final String FIELD_CONNECTION = "connection";
public static final String FIELD_HTTP_URL = "url";

public static final String CONNECTION_GETTER = "com.navercorp.pinpoint.plugin.okhttp.ConnectionGetter";
public static final String HTTP_URL_GETTER = "com.navercorp.pinpoint.plugin.okhttp.HttpUrlGetter";
public static final String URL_GETTER = "com.navercorp.pinpoint.plugin.okhttp.UrlGetter";
public static final String USER_REQUEST_GETTER = "com.navercorp.pinpoint.plugin.okhttp.UserRequestGetter";
public static final String USER_RESPONSE_GETTER = "com.navercorp.pinpoint.plugin.okhttp.UserResponseGetter";
public static final String CONNECTION_GETTER = "com.navercorp.pinpoint.plugin.okhttp.v2.ConnectionGetter";
public static final String HTTP_URL_GETTER = "com.navercorp.pinpoint.plugin.okhttp.v2.HttpUrlGetter";
public static final String URL_GETTER = "com.navercorp.pinpoint.plugin.okhttp.v2.UrlGetter";
public static final String USER_REQUEST_GETTER = "com.navercorp.pinpoint.plugin.okhttp.v2.UserRequestGetter";
public static final String USER_RESPONSE_GETTER = "com.navercorp.pinpoint.plugin.okhttp.v2.UserResponseGetter";
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@
*/
public class OkHttpPluginConfig {

private boolean param = false;
private boolean cookie = false;
private DumpType cookieDumpType = DumpType.EXCEPTION;
private int cookieSamplingRate = 1;
private boolean statusCode = true;

private final boolean enable;
private final boolean param;
private final boolean cookie;
private final int cookieSamplingRate;
private final boolean statusCode;
private final boolean async;
private DumpType cookieDumpType;

public OkHttpPluginConfig(ProfilerConfig src) {
this.enable = src.readBoolean("profiler.okhttp.enable", true);
this.param = src.readBoolean("profiler.okhttp.param", false);
this.cookie = src.readBoolean("profiler.okhttp.cookie", false);
this.cookieDumpType = src.readDumpType("profiler.okhttp.cookie.dumptype", DumpType.EXCEPTION);
Expand All @@ -42,6 +43,10 @@ public OkHttpPluginConfig(ProfilerConfig src) {
this.async = src.readBoolean("profiler.okhttp.async", true);
}

public boolean isEnable() {
return enable;
}

public boolean isParam() {
return param;
}
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 NAVER Corp.
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,28 +13,29 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.plugin.okhttp.interceptor;

import com.navercorp.pinpoint.bootstrap.context.AsyncTraceId;
import com.navercorp.pinpoint.bootstrap.context.AsyncContext;
import com.navercorp.pinpoint.bootstrap.context.MethodDescriptor;
import com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder;
import com.navercorp.pinpoint.bootstrap.context.TraceContext;
import com.navercorp.pinpoint.bootstrap.interceptor.SpanAsyncEventSimpleAroundInterceptor;
import com.navercorp.pinpoint.bootstrap.interceptor.AsyncContextSpanEventSimpleAroundInterceptor;
import com.navercorp.pinpoint.plugin.okhttp.OkHttpConstants;

/**
*
* @author jaehong.kim
*
*/
public class AsyncCallExecuteMethodInterceptor extends SpanAsyncEventSimpleAroundInterceptor {
public class AsyncCallExecuteMethodInterceptor extends AsyncContextSpanEventSimpleAroundInterceptor {

public AsyncCallExecuteMethodInterceptor(TraceContext traceContext, MethodDescriptor descriptor) {
super(traceContext, descriptor);
}

@Override
protected void doInBeforeTrace(SpanEventRecorder recorder, AsyncTraceId asyncTraceId, Object target, Object[] args) {
protected void doInBeforeTrace(SpanEventRecorder recorder, AsyncContext asyncContext, Object target, Object[] args) {
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2014 NAVER Corp.
* Copyright 2017 NAVER Corp.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -13,6 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.navercorp.pinpoint.plugin.okhttp.interceptor;

import com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor;
Expand All @@ -27,9 +28,7 @@
import com.navercorp.pinpoint.plugin.okhttp.OkHttpConstants;

/**
*
* @author jaehong.kim
*
*/
public class DispatcherEnqueueMethodInterceptor implements AroundInterceptor {
private final PLogger logger = PLoggerFactory.getLogger(this.getClass());
Expand Down Expand Up @@ -62,9 +61,8 @@ public void before(Object target, Object[] args) {
try {
// set asynchronous trace
final AsyncContext asyncContext = recorder.recordNextAsyncContext();

// AsyncTraceIdAccessor typeCheck validate();
((AsyncContextAccessor)args[0])._$PINPOINT$_setAsyncContext(asyncContext);
((AsyncContextAccessor) args[0])._$PINPOINT$_setAsyncContext(asyncContext);
if (isDebug) {
logger.debug("Set AsyncContext {}", asyncContext);
}
Expand All @@ -75,7 +73,9 @@ public void before(Object target, Object[] args) {

private boolean validate(Object[] args) {
if (args == null || args.length < 1 || !(args[0] instanceof AsyncContextAccessor)) {
logger.debug("Invalid args[0] object {}. Need field accessor({}).", args, AsyncContextAccessor.class.getName());
if (isDebug) {
logger.debug("Invalid args[0] object {}. Need field accessor({}).", args, AsyncContextAccessor.class.getName());
}
return false;
}

Expand All @@ -98,7 +98,7 @@ public void after(Object target, Object[] args, Object result, Throwable throwab
}

try {
SpanEventRecorder recorder = trace.currentSpanEventRecorder();
final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
recorder.recordApi(methodDescriptor);
recorder.recordServiceType(OkHttpConstants.OK_HTTP_CLIENT_INTERNAL);
recorder.recordException(throwable);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 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.okhttp.v2;

import com.squareup.okhttp.Connection;

/**
* @author jaehong.kim
*/
public interface ConnectionGetter {
Connection _$PINPOINT$_getConnection();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright 2017 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.okhttp.v2;

import com.squareup.okhttp.HttpUrl;

/**
* @author jaehong.kim
*/
public interface HttpUrlGetter {
HttpUrl _$PINPOINT$_getHttpUrl();
}
Loading

0 comments on commit 80d0866

Please sign in to comment.