Search in sources :

Example 51 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class HttpRequestExecutorExecuteMethodInterceptor method recordEntity.

protected void recordEntity(HttpMessage httpMessage, Trace trace) {
    if (httpMessage instanceof HttpEntityEnclosingRequest) {
        final HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) httpMessage;
        try {
            final HttpEntity entity = entityRequest.getEntity();
            if (entity != null && entity.isRepeatable() && entity.getContentLength() > 0) {
                if (entitySampler.isSampling()) {
                    final String entityString = entityUtilsToString(entity, "UTF8", 1024);
                    final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
                    recorder.recordAttribute(AnnotationKey.HTTP_PARAM_ENTITY, entityString);
                }
            }
        } catch (Exception e) {
            logger.debug("HttpEntityEnclosingRequest entity record fail. Caused:{}", e.getMessage(), e);
        }
    }
}
Also used : HttpEntity(org.apache.http.HttpEntity) HttpEntityEnclosingRequest(org.apache.http.HttpEntityEnclosingRequest) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) ParseException(org.apache.http.ParseException) IOException(java.io.IOException)

Example 52 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class CassandraStatementExecuteQueryInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    SpanEventRecorder recorder = trace.traceBlockBegin();
    try {
        DatabaseInfo databaseInfo = (target instanceof DatabaseInfoAccessor) ? ((DatabaseInfoAccessor) target)._$PINPOINT$_getDatabaseInfo() : null;
        if (databaseInfo == null) {
            databaseInfo = UnKnownDatabaseInfo.INSTANCE;
        }
        recorder.recordServiceType(databaseInfo.getExecuteQueryType());
        recorder.recordEndPoint(databaseInfo.getMultipleHost());
        recorder.recordDestinationId(databaseInfo.getDatabaseId());
        String sql;
        if (args[0] instanceof BoundStatement) {
            sql = ((BoundStatement) args[0]).preparedStatement().getQueryString();
        } else if (args[0] instanceof RegularStatement) {
            sql = ((RegularStatement) args[0]).getQueryString();
        } else {
            // we have string
            sql = (String) args[0];
        }
        ParsingResult parsingResult = traceContext.parseSql(sql);
        if (parsingResult != null) {
            ((ParsingResultAccessor) target)._$PINPOINT$_setParsingResult(parsingResult);
        } else {
            if (logger.isErrorEnabled()) {
                logger.error("sqlParsing fail. parsingResult is null sql:{}", sql);
            }
        }
        Map<Integer, String> bindValue = ((BindValueAccessor) target)._$PINPOINT$_getBindValue();
        // Extracting bind variables from already-serialized is too risky
        if (bindValue != null && !bindValue.isEmpty()) {
            String bindString = toBindVariable(bindValue);
            recorder.recordSqlParsingResult(parsingResult, bindString);
        } else {
            recorder.recordSqlParsingResult(parsingResult);
        }
        recorder.recordApi(descriptor);
        clean(target);
    } catch (Exception e) {
        if (logger.isWarnEnabled()) {
            logger.warn(e.getMessage(), e);
        }
    }
}
Also used : UnKnownDatabaseInfo(com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo) DatabaseInfo(com.navercorp.pinpoint.bootstrap.context.DatabaseInfo) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) DatabaseInfoAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor) BindValueAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor) ParsingResultAccessor(com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor) RegularStatement(com.datastax.driver.core.RegularStatement) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) ParsingResult(com.navercorp.pinpoint.bootstrap.context.ParsingResult) BoundStatement(com.datastax.driver.core.BoundStatement)

Example 53 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class CxfClientInvokeSyncMethodInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        if (isDebug) {
            logger.debug("Sampling is disabled");
        }
        return;
    }
    String endpoint = getDestination(args);
    String operation = getOperation(args);
    Object[] parameters = getParameters(operation, args);
    SpanEventRecorder recorder = trace.traceBlockBegin();
    TraceId nextId = trace.getTraceId().getNextTraceId();
    recorder.recordNextSpanId(nextId.getSpanId());
    recorder.recordServiceType(CxfPluginConstants.CXF_CLIENT_SERVICE_TYPE);
    recorder.recordDestinationId(endpoint);
    recorder.recordAttribute(CxfPluginConstants.CXF_OPERATION, operation);
    recorder.recordAttribute(CxfPluginConstants.CXF_ARGS, Arrays.toString(parameters));
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId)

Example 54 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class DefaultClientExchangeHandlerImplStartMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        final HttpRequest httpRequest = getHttpRequest(target);
        if (httpRequest != null) {
            // Accessing httpRequest here not BEFORE() because it can cause side effect.
            if (httpRequest.getRequestLine() != null) {
                final String httpUrl = InterceptorUtils.getHttpUrl(httpRequest.getRequestLine().getUri(), param);
                recorder.recordAttribute(AnnotationKey.HTTP_URL, httpUrl);
            }
            final NameIntValuePair<String> host = getHost(target);
            if (host != null) {
                final String endpoint = getEndpoint(host.getName(), host.getValue());
                recorder.recordDestinationId(endpoint);
            }
            recordHttpRequest(recorder, httpRequest, throwable);
        }
        recorder.recordApi(methodDescriptor);
        recorder.recordException(throwable);
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) HttpRequest(org.apache.http.HttpRequest) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Example 55 with SpanEventRecorder

use of com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder in project pinpoint by naver.

the class DefaultHttpRequestRetryHandlerRetryRequestMethodInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args);
    }
    final Trace trace = traceContext.currentTraceObject();
    if (trace == null) {
        return;
    }
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(descriptor);
        recorder.recordException(throwable);
        // arguments(final IOException exception, final int executionCount, final HttpContext context)
        final StringBuilder sb = new StringBuilder();
        if (args != null && args.length >= 1 && args[0] != null && args[0] instanceof Exception) {
            sb.append(args[0].getClass().getName()).append(", ");
        }
        if (args != null && args.length >= 2 && args[1] != null && args[1] instanceof Integer) {
            sb.append(args[1]);
        }
        recorder.recordAttribute(AnnotationKey.HTTP_INTERNAL_DISPLAY, sb.toString());
        if (result != null) {
            recorder.recordAttribute(AnnotationKey.RETURN_DATA, result);
        }
    } finally {
        trace.traceBlockEnd();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)

Aggregations

SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)86 Trace (com.navercorp.pinpoint.bootstrap.context.Trace)75 AsyncTraceId (com.navercorp.pinpoint.bootstrap.context.AsyncTraceId)12 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)9 AsyncTraceIdAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncTraceIdAccessor)8 InterceptorScopeInvocation (com.navercorp.pinpoint.bootstrap.interceptor.scope.InterceptorScopeInvocation)8 DatabaseInfoAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DatabaseInfoAccessor)5 DatabaseInfo (com.navercorp.pinpoint.bootstrap.context.DatabaseInfo)4 Socket (java.net.Socket)3 HttpRequest (org.apache.http.HttpRequest)3 Test (org.junit.Test)3 MethodDescriptor (com.navercorp.pinpoint.bootstrap.context.MethodDescriptor)2 ParsingResult (com.navercorp.pinpoint.bootstrap.context.ParsingResult)2 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)2 TraceContext (com.navercorp.pinpoint.bootstrap.context.TraceContext)2 BindValueAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.BindValueAccessor)2 DefaultDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.DefaultDatabaseInfo)2 JdbcUrlParser (com.navercorp.pinpoint.bootstrap.plugin.jdbc.JdbcUrlParser)2 ParsingResultAccessor (com.navercorp.pinpoint.bootstrap.plugin.jdbc.ParsingResultAccessor)2 UnKnownDatabaseInfo (com.navercorp.pinpoint.bootstrap.plugin.jdbc.UnKnownDatabaseInfo)2