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);
}
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;
}
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;
}
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();
}
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"));
}
Aggregations