Search in sources :

Example 1 with LogMarkerMethodDescriptor

use of com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor in project pinpoint by naver.

the class TransactionIdStartedInterceptor method after.

@Override
public void after(Object target, Object[] args, Object result, Throwable throwable) {
    if (isDebug) {
        logger.afterInterceptor(target, args, result, throwable);
    }
    AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
    if (asyncContext == null) {
        logger.debug("Not found asynchronous invocation metadata");
        return;
    }
    if (isDebug) {
        logger.debug("Asynchronous invocation. asyncContext={}", asyncContext);
    }
    final Trace trace = asyncContext.currentAsyncTraceObject();
    if (trace == null) {
        return;
    }
    if (isDebug) {
        logger.debug("Asynchronous invocation. asyncTraceId={}, trace={}", asyncContext, trace);
    }
    traceContext.removeTraceObject();
    try {
        final SpanEventRecorder recorder = trace.currentSpanEventRecorder();
        LogMarkerToken logMarkerToken = (LogMarkerToken) args[2];
        String message = ((Function0) args[3]).apply().toString();
        recorder.recordApi(new LogMarkerMethodDescriptor(logMarkerToken));
        if (logMarkerToken.component().equals("database")) {
            recorder.recordServiceType(OpenwhiskConstants.COUCHDB_EXECUTE_QUERY);
            recorder.recordDestinationId("COUCHDB");
            recorder.recordAttribute(OpenwhiskConstants.MARKER_MESSAGE, message);
        } else {
            recorder.recordServiceType(OpenwhiskConstants.OPENWHISK_INTERNAL);
            if (isLoggingMessage && message.length() > 0) {
                recorder.recordAttribute(OpenwhiskConstants.MARKER_MESSAGE, message);
            }
        }
        if (result instanceof AsyncContextAccessor && result instanceof PinpointTraceAccessor) {
            ((AsyncContextAccessor) (result))._$PINPOINT$_setAsyncContext(asyncContext);
            ((PinpointTraceAccessor) (result))._$PINPOINT$_setPinpointTrace(trace);
        }
    } catch (Throwable th) {
        if (logger.isWarnEnabled()) {
            logger.warn("AFTER error. Caused:{}", th.getMessage(), th);
        }
    }
}
Also used : LogMarkerMethodDescriptor(com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor) AsyncContextAccessor(com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor) PinpointTraceAccessor(com.navercorp.pinpoint.plugin.openwhisk.accessor.PinpointTraceAccessor) LogMarkerToken(org.apache.openwhisk.common.LogMarkerToken)

Example 2 with LogMarkerMethodDescriptor

use of com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor in project pinpoint by naver.

the class TransactionIdMarkInterceptor method before.

/**
 * @param target
 * @param args TransactionMetadata, Identify, LogMarkerToken
 */
@Override
public void before(Object target, Object[] args) {
    if (isDebug) {
        logger.beforeInterceptor(target, args);
    }
    AsyncContext asyncContext = AsyncContextAccessorUtils.getAsyncContext(args, 0);
    if (asyncContext == null) {
        logger.debug("Not found asynchronous invocation metadata {}", (LogMarkerToken) args[2]);
        return;
    }
    Trace trace = asyncContext.continueAsyncTraceObject();
    if (trace == null) {
        logger.debug("trace object null");
        return;
    }
    final SpanEventRecorder recorder = trace.traceBlockBegin();
    recorder.recordServiceType(OpenwhiskConstants.OPENWHISK_INTERNAL);
    try {
        LogMarkerToken logMarkerToken = (LogMarkerToken) args[2];
        String message = ((Function0) args[3]).apply().toString();
        recorder.recordApi(new LogMarkerMethodDescriptor(logMarkerToken));
        if (isLoggingMessage && message.length() > 0) {
            recorder.recordAttribute(OpenwhiskConstants.MARKER_MESSAGE, message);
        }
    } finally {
        trace.traceBlockEnd();
        trace.close();
        asyncContext.close();
    }
}
Also used : LogMarkerMethodDescriptor(com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor) LogMarkerToken(org.apache.openwhisk.common.LogMarkerToken)

Aggregations

LogMarkerMethodDescriptor (com.navercorp.pinpoint.plugin.openwhisk.descriptor.LogMarkerMethodDescriptor)2 LogMarkerToken (org.apache.openwhisk.common.LogMarkerToken)2 AsyncContextAccessor (com.navercorp.pinpoint.bootstrap.async.AsyncContextAccessor)1 PinpointTraceAccessor (com.navercorp.pinpoint.plugin.openwhisk.accessor.PinpointTraceAccessor)1