Skip to content
This repository was archived by the owner on Dec 23, 2023. It is now read-only.

Commit 5be7044

Browse files
authored
Add more InstanaExporterHandler tests (#2014)
1 parent f7e0a66 commit 5be7044

File tree

1 file changed

+159
-0
lines changed

1 file changed

+159
-0
lines changed

exporters/trace/instana/src/test/java/io/opencensus/exporter/trace/instana/InstanaExporterHandlerTest.java

Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,4 +175,163 @@ public void generateSpan_ClientKind() {
175175
+ "}"
176176
+ "]");
177177
}
178+
179+
@Test
180+
public void generateSpan_NullStatus() {
181+
SpanData data =
182+
SpanData.create(
183+
SpanContext.create(
184+
TraceId.fromLowerBase16(TRACE_ID),
185+
SpanId.fromLowerBase16(SPAN_ID),
186+
TraceOptions.builder().setIsSampled(true).build()),
187+
SpanId.fromLowerBase16(PARENT_SPAN_ID),
188+
true, /* hasRemoteParent */
189+
"SpanName", /* name */
190+
null, /* kind */
191+
Timestamp.create(1505855794, 194009601) /* startTimestamp */,
192+
Attributes.create(attributes, 0 /* droppedAttributesCount */),
193+
TimedEvents.create(annotations, 0 /* droppedEventsCount */),
194+
TimedEvents.create(messageEvents, 0 /* droppedEventsCount */),
195+
Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */),
196+
null, /* childSpanCount */
197+
null, /* status */
198+
Timestamp.create(1505855799, 465726528) /* endTimestamp */);
199+
200+
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data)))
201+
.isEqualTo("[]");
202+
}
203+
204+
@Test
205+
public void generateSpan_ErrorStatus() {
206+
SpanData data =
207+
SpanData.create(
208+
SpanContext.create(
209+
TraceId.fromLowerBase16(TRACE_ID),
210+
SpanId.fromLowerBase16(SPAN_ID),
211+
TraceOptions.builder().setIsSampled(true).build()),
212+
SpanId.fromLowerBase16(PARENT_SPAN_ID),
213+
true, /* hasRemoteParent */
214+
"SpanName", /* name */
215+
Kind.CLIENT, /* kind */
216+
Timestamp.create(1505855794, 194009601) /* startTimestamp */,
217+
Attributes.create(attributes, 0 /* droppedAttributesCount */),
218+
TimedEvents.create(annotations, 0 /* droppedEventsCount */),
219+
TimedEvents.create(messageEvents, 0 /* droppedEventsCount */),
220+
Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */),
221+
null, /* childSpanCount */
222+
Status.OUT_OF_RANGE, /* status, any but OK */
223+
Timestamp.create(1505855799, 465726528) /* endTimestamp */);
224+
225+
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data)))
226+
.isEqualTo(
227+
"["
228+
+ "{"
229+
+ "\"spanId\":\"9cc1e3049173be09\","
230+
+ "\"traceId\":\"d239036e7d5cec11\","
231+
+ "\"parentId\":\"8b03ab423da481c5\","
232+
+ "\"timestamp\":1505855794194,"
233+
+ "\"duration\":5271,"
234+
+ "\"name\":\"SpanName\","
235+
+ "\"type\":\"EXIT\","
236+
+ "\"error\":true,"
237+
+ "\"data\":"
238+
+ "{\"http.url\":\"http://localhost/foo\"}"
239+
+ "}"
240+
+ "]");
241+
}
242+
243+
@Test
244+
public void generateSpan_MultipleSpans() {
245+
SpanData data =
246+
SpanData.create(
247+
SpanContext.create(
248+
TraceId.fromLowerBase16(TRACE_ID),
249+
SpanId.fromLowerBase16(SPAN_ID),
250+
TraceOptions.builder().setIsSampled(true).build()),
251+
SpanId.fromLowerBase16(PARENT_SPAN_ID),
252+
true, /* hasRemoteParent */
253+
"SpanName", /* name */
254+
Kind.CLIENT, /* kind */
255+
Timestamp.create(1505855794, 194009601) /* startTimestamp */,
256+
Attributes.create(attributes, 0 /* droppedAttributesCount */),
257+
TimedEvents.create(annotations, 0 /* droppedEventsCount */),
258+
TimedEvents.create(messageEvents, 0 /* droppedEventsCount */),
259+
Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */),
260+
null, /* childSpanCount */
261+
Status.OK,
262+
Timestamp.create(1505855799, 465726528) /* endTimestamp */);
263+
264+
assertThat(InstanaExporterHandler.convertToJson(Collections.nCopies(2, data)))
265+
.isEqualTo(
266+
"["
267+
+ "{"
268+
+ "\"spanId\":\"9cc1e3049173be09\","
269+
+ "\"traceId\":\"d239036e7d5cec11\","
270+
+ "\"parentId\":\"8b03ab423da481c5\","
271+
+ "\"timestamp\":1505855794194,"
272+
+ "\"duration\":5271,"
273+
+ "\"name\":\"SpanName\","
274+
+ "\"type\":\"EXIT\","
275+
+ "\"data\":"
276+
+ "{\"http.url\":\"http://localhost/foo\"}"
277+
+ "},"
278+
+ "{"
279+
+ "\"spanId\":\"9cc1e3049173be09\","
280+
+ "\"traceId\":\"d239036e7d5cec11\","
281+
+ "\"parentId\":\"8b03ab423da481c5\","
282+
+ "\"timestamp\":1505855794194,"
283+
+ "\"duration\":5271,"
284+
+ "\"name\":\"SpanName\","
285+
+ "\"type\":\"EXIT\","
286+
+ "\"data\":"
287+
+ "{\"http.url\":\"http://localhost/foo\"}"
288+
+ "}"
289+
+ "]");
290+
}
291+
292+
@Test
293+
public void generateSpan_MultipleAttributes() {
294+
Map<String, AttributeValue> multipleAttributes =
295+
ImmutableMap.of(
296+
"http.url", AttributeValue.stringAttributeValue("http://localhost/foo"),
297+
"http.method", AttributeValue.stringAttributeValue("GET"));
298+
299+
SpanData data =
300+
SpanData.create(
301+
SpanContext.create(
302+
TraceId.fromLowerBase16(TRACE_ID),
303+
SpanId.fromLowerBase16(SPAN_ID),
304+
TraceOptions.builder().setIsSampled(true).build()),
305+
SpanId.fromLowerBase16(PARENT_SPAN_ID),
306+
true, /* hasRemoteParent */
307+
"SpanName", /* name */
308+
Kind.CLIENT, /* kind */
309+
Timestamp.create(1505855794, 194009601) /* startTimestamp */,
310+
Attributes.create(multipleAttributes, 0 /* droppedAttributesCount */),
311+
TimedEvents.create(annotations, 0 /* droppedEventsCount */),
312+
TimedEvents.create(messageEvents, 0 /* droppedEventsCount */),
313+
Links.create(Collections.<Link>emptyList(), 0 /* droppedLinksCount */),
314+
null, /* childSpanCount */
315+
Status.OK,
316+
Timestamp.create(1505855799, 465726528) /* endTimestamp */);
317+
318+
assertThat(InstanaExporterHandler.convertToJson(Collections.singletonList(data)))
319+
.isEqualTo(
320+
"["
321+
+ "{"
322+
+ "\"spanId\":\"9cc1e3049173be09\","
323+
+ "\"traceId\":\"d239036e7d5cec11\","
324+
+ "\"parentId\":\"8b03ab423da481c5\","
325+
+ "\"timestamp\":1505855794194,"
326+
+ "\"duration\":5271,"
327+
+ "\"name\":\"SpanName\","
328+
+ "\"type\":\"EXIT\","
329+
+ "\"data\":"
330+
+ "{"
331+
+ "\"http.url\":\"http://localhost/foo\","
332+
+ "\"http.method\":\"GET\""
333+
+ "}"
334+
+ "}"
335+
+ "]");
336+
}
178337
}

0 commit comments

Comments
 (0)