Search in sources :

Example 6 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class SyncHttpRequestSendInterceptorTest method testMethodsAroundError.

@Test
public void testMethodsAroundError() throws Throwable {
    interceptor.beforeMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    interceptor.handleMethodException(enhancedInstance, null, allArguments, argumentTypes, new RuntimeException());
    interceptor.afterMethod(enhancedInstance, null, allArguments, argumentTypes, null);
    assertThat(segmentStorage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = segmentStorage.getTraceSegments().get(0);
    Assert.assertEquals(1, SegmentHelper.getSpans(traceSegment).size());
    AbstractTracingSpan finishedSpan = SegmentHelper.getSpans(traceSegment).get(0);
    List<KeyValuePair> tags = SpanHelper.getTags(finishedSpan);
    assertThat(tags.size(), is(2));
    assertThat(tags.get(0).getValue(), is("GET"));
    assertThat(tags.get(1).getValue(), is(uri.toString()));
    Assert.assertEquals(true, SpanHelper.getErrorOccurred(finishedSpan));
    SpanAssert.assertException(SpanHelper.getLogs(finishedSpan).get(0), RuntimeException.class);
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Example 7 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class AbstractTracingSpan method transform.

public SpanObject.Builder transform() {
    SpanObject.Builder spanBuilder = SpanObject.newBuilder();
    spanBuilder.setSpanId(this.spanId);
    spanBuilder.setParentSpanId(parentSpanId);
    spanBuilder.setStartTime(startTime);
    spanBuilder.setEndTime(endTime);
    if (operationId != DictionaryUtil.nullValue()) {
        spanBuilder.setOperationNameId(operationId);
    } else {
        spanBuilder.setOperationName(operationName);
    }
    if (isEntry()) {
        spanBuilder.setSpanType(SpanType.Entry);
    } else if (isExit()) {
        spanBuilder.setSpanType(SpanType.Exit);
    } else {
        spanBuilder.setSpanType(SpanType.Local);
    }
    if (this.layer != null) {
        spanBuilder.setSpanLayerValue(this.layer.getCode());
    }
    if (componentId != DictionaryUtil.nullValue()) {
        spanBuilder.setComponentId(componentId);
    } else {
        if (componentName != null) {
            spanBuilder.setComponent(componentName);
        }
    }
    spanBuilder.setIsError(errorOccurred);
    if (this.tags != null) {
        for (KeyValuePair tag : this.tags) {
            spanBuilder.addTags(tag.transform());
        }
    }
    if (this.logs != null) {
        for (LogDataEntity log : this.logs) {
            spanBuilder.addLogs(log.transform());
        }
    }
    if (this.refs != null) {
        for (TraceSegmentRef ref : this.refs) {
            spanBuilder.addRefs(ref.transform());
        }
    }
    return spanBuilder;
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) SpanObject(org.apache.skywalking.apm.network.proto.SpanObject)

Example 8 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class AbstractTracingSpan method log.

/**
 * Record a common log with multi fields, for supporting opentracing-java
 *
 * @param fields
 * @return the Span, for chaining
 */
@Override
public AbstractTracingSpan log(long timestampMicroseconds, Map<String, ?> fields) {
    if (logs == null) {
        logs = new LinkedList<LogDataEntity>();
    }
    LogDataEntity.Builder builder = new LogDataEntity.Builder();
    for (Map.Entry<String, ?> entry : fields.entrySet()) {
        builder.add(new KeyValuePair(entry.getKey(), entry.getValue().toString()));
    }
    logs.add(builder.build(timestampMicroseconds));
    return this;
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) Map(java.util.Map)

Example 9 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class LogDataEntity method transform.

public LogMessage transform() {
    LogMessage.Builder logMessageBuilder = LogMessage.newBuilder();
    for (KeyValuePair log : logs) {
        logMessageBuilder.addData(log.transform());
    }
    logMessageBuilder.setTime(timestamp);
    return logMessageBuilder.build();
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) LogMessage(org.apache.skywalking.apm.network.proto.LogMessage)

Example 10 with KeyValuePair

use of org.apache.skywalking.apm.agent.core.context.util.KeyValuePair in project incubator-skywalking by apache.

the class TraceAnnotationTest method testTraceWithOperationName.

@Test
public void testTraceWithOperationName() throws Throwable {
    Method withOperationNameMethod = TestAnnotationMethodClass.class.getDeclaredMethod("testMethodWithOperationName");
    methodInterceptor.beforeMethod(enhancedInstance, withOperationNameMethod, null, null, null);
    tagInterceptor.beforeMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null);
    tagInterceptor.afterMethod(TestAnnotationMethodClass.class, withOperationNameMethod, tagParameters, tagParameterTypes, null);
    methodInterceptor.afterMethod(enhancedInstance, withOperationNameMethod, null, null, null);
    assertThat(storage.getTraceSegments().size(), is(1));
    TraceSegment traceSegment = storage.getTraceSegments().get(0);
    List<AbstractTracingSpan> spans = SegmentHelper.getSpans(traceSegment);
    assertThat(spans.size(), is(1));
    AbstractTracingSpan tracingSpan = spans.get(0);
    assertThat(tracingSpan.getOperationName(), is("testMethod"));
    SpanAssert.assertLogSize(tracingSpan, 0);
    SpanAssert.assertTagSize(tracingSpan, 1);
    List<KeyValuePair> tags = SpanHelper.getTags(tracingSpan);
    assertThat(tags.get(0).getKey(), is("testTagKey"));
    assertThat(tags.get(0).getValue(), is("testTagValue"));
}
Also used : KeyValuePair(org.apache.skywalking.apm.agent.core.context.util.KeyValuePair) AbstractTracingSpan(org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan) Method(java.lang.reflect.Method) TraceSegment(org.apache.skywalking.apm.agent.core.context.trace.TraceSegment) Test(org.junit.Test)

Aggregations

KeyValuePair (org.apache.skywalking.apm.agent.core.context.util.KeyValuePair)13 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)10 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)10 Test (org.junit.Test)10 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 Response (feign.Response)3 Method (java.lang.reflect.Method)1 Map (java.util.Map)1 AbstractSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractSpan)1 LogDataEntity (org.apache.skywalking.apm.agent.core.context.trace.LogDataEntity)1 LogMessage (org.apache.skywalking.apm.network.proto.LogMessage)1 SpanObject (org.apache.skywalking.apm.network.proto.SpanObject)1