Search in sources :

Example 1 with Method

use of com.rabbitmq.client.impl.Method in project pinpoint by naver.

the class RabbitMQConsumerHandleCompleteInboundCommandInterceptor method createTrace.

private Trace createTrace(AMQChannel amqChannel, AMQCommand amqCommand) {
    AMQConnection connection = amqChannel.getConnection();
    if (connection == null) {
        logger.debug("connection is null, skipping trace");
    }
    Method method = amqCommand.getMethod();
    AMQP.Basic.GetOk getOk = (AMQP.Basic.GetOk) method;
    String exchange = getOk.getExchange();
    if (RabbitMQClientPluginConfig.isExchangeExcluded(exchange, excludeExchangeFilter)) {
        if (isDebug) {
            logger.debug("exchange {} is excluded", exchange);
        }
        return null;
    }
    String routingKey = getOk.getRoutingKey();
    Map<String, Object> headers = getHeadersFromContentHeader(amqCommand.getContentHeader());
    // If this transaction is not traceable, mark as disabled.
    if (headers.get(RabbitMQClientConstants.META_SAMPLED) != null) {
        return traceContext.disableSampling();
    }
    final TraceId traceId = populateTraceIdFromRequest(headers);
    // If there's no trasanction id, a new trasaction begins here.
    final Trace trace = traceId == null ? traceContext.newTraceObject() : traceContext.continueTraceObject(traceId);
    if (trace.canSampled()) {
        final SpanRecorder recorder = trace.getSpanRecorder();
        recordRootSpan(recorder, connection, exchange, routingKey, headers);
    }
    return trace;
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) SpanRecorder(com.navercorp.pinpoint.bootstrap.context.SpanRecorder) AMQConnection(com.rabbitmq.client.impl.AMQConnection) AMQP(com.rabbitmq.client.AMQP) TraceId(com.navercorp.pinpoint.bootstrap.context.TraceId) Method(com.rabbitmq.client.impl.Method)

Example 2 with Method

use of com.rabbitmq.client.impl.Method in project pinpoint by naver.

the class RabbitMQConsumerHandleCompleteInboundCommandInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (!validate(target, args)) {
        return;
    }
    AMQCommand command = (AMQCommand) args[0];
    Method method = command.getMethod();
    if (!(method instanceof AMQP.Basic.GetOk)) {
        return;
    }
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    final Trace trace = traceContext.currentRawTraceObject();
    if (trace == null) {
        return;
    }
    if (!trace.canSampled()) {
        traceContext.removeTraceObject();
    }
    try {
        SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        recorder.recordApi(methodDescriptor);
        if (throwable != null) {
            recorder.recordException(throwable);
        }
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER. Caused:{}", th.getMessage(), th);
        }
    } finally {
        traceContext.removeTraceObject();
        trace.traceBlockEnd();
        trace.close();
    }
}
Also used : Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AMQP(com.rabbitmq.client.AMQP) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Method(com.rabbitmq.client.impl.Method) AMQCommand(com.rabbitmq.client.impl.AMQCommand)

Example 3 with Method

use of com.rabbitmq.client.impl.Method in project pinpoint by naver.

the class RabbitMQConsumerHandleCompleteInboundCommandInterceptor method before.

@Override
public void before(Object target, Object[] args) {
    if (!validate(target, args)) {
        return;
    }
    AMQCommand command = (AMQCommand) args[0];
    Method method = command.getMethod();
    if (!(method instanceof AMQP.Basic.GetOk)) {
        return;
    }
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    try {
        AMQChannel channel = (AMQChannel) target;
        final Trace trace = createTrace(channel, command);
        if (trace == null) {
            return;
        }
        if (!trace.canSampled()) {
            return;
        }
        SpanEventRecorder recorder = trace.traceBlockBegin();
        recorder.recordServiceType(RabbitMQClientConstants.RABBITMQ_CLIENT_INTERNAL);
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("BEFORE. Caused:{}", th.getMessage(), th);
        }
    }
}
Also used : AMQChannel(com.rabbitmq.client.impl.AMQChannel) Trace(com.navercorp.pinpoint.bootstrap.context.Trace) AMQP(com.rabbitmq.client.AMQP) SpanEventRecorder(com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder) Method(com.rabbitmq.client.impl.Method) AMQCommand(com.rabbitmq.client.impl.AMQCommand)

Aggregations

Trace (com.navercorp.pinpoint.bootstrap.context.Trace)3 AMQP (com.rabbitmq.client.AMQP)3 Method (com.rabbitmq.client.impl.Method)3 SpanEventRecorder (com.navercorp.pinpoint.bootstrap.context.SpanEventRecorder)2 AMQCommand (com.rabbitmq.client.impl.AMQCommand)2 SpanRecorder (com.navercorp.pinpoint.bootstrap.context.SpanRecorder)1 TraceId (com.navercorp.pinpoint.bootstrap.context.TraceId)1 AMQChannel (com.rabbitmq.client.impl.AMQChannel)1 AMQConnection (com.rabbitmq.client.impl.AMQConnection)1