|
53 | 53 |
|
54 | 54 | @RunWith(JUnit4.class) |
55 | 55 | public final class StackdriverV2ExporterHandlerProtoTest { |
| 56 | + |
56 | 57 | private static final Credentials FAKE_CREDENTIALS = |
57 | 58 | GoogleCredentials.newBuilder().setAccessToken(new AccessToken("fake", new Date(100))).build(); |
58 | 59 | // OpenCensus constants |
@@ -141,7 +142,6 @@ public void generateSpan() { |
141 | 142 | CHILD_SPAN_COUNT, |
142 | 143 | status, |
143 | 144 | endTimestamp); |
144 | | - |
145 | 145 | TimeEvent annotationTimeEvent1 = |
146 | 146 | TimeEvent.newBuilder() |
147 | 147 | .setAnnotation( |
@@ -255,4 +255,55 @@ public void generateSpan() { |
255 | 255 | assertThat(span.getChildSpanCount()) |
256 | 256 | .isEqualTo(Int32Value.newBuilder().setValue(CHILD_SPAN_COUNT).build()); |
257 | 257 | } |
| 258 | + |
| 259 | + @Test |
| 260 | + public void mapHttpAttributes() { |
| 261 | + Map<String, io.opencensus.trace.AttributeValue> attributesMap = |
| 262 | + new HashMap<String, io.opencensus.trace.AttributeValue>(); |
| 263 | + |
| 264 | + attributesMap.put("http.host", io.opencensus.trace.AttributeValue.stringAttributeValue("host")); |
| 265 | + attributesMap.put( |
| 266 | + "http.method", io.opencensus.trace.AttributeValue.stringAttributeValue("method")); |
| 267 | + attributesMap.put("http.path", io.opencensus.trace.AttributeValue.stringAttributeValue("path")); |
| 268 | + attributesMap.put( |
| 269 | + "http.route", io.opencensus.trace.AttributeValue.stringAttributeValue("route")); |
| 270 | + attributesMap.put( |
| 271 | + "http.user_agent", io.opencensus.trace.AttributeValue.stringAttributeValue("user_agent")); |
| 272 | + attributesMap.put( |
| 273 | + "http.status_code", io.opencensus.trace.AttributeValue.longAttributeValue(200L)); |
| 274 | + SpanData.Attributes httpAttributes = SpanData.Attributes.create(attributesMap, 0); |
| 275 | + |
| 276 | + SpanData spanData = |
| 277 | + SpanData.create( |
| 278 | + spanContext, |
| 279 | + parentSpanId, |
| 280 | + /* hasRemoteParent= */ true, |
| 281 | + SPAN_NAME, |
| 282 | + startTimestamp, |
| 283 | + httpAttributes, |
| 284 | + annotations, |
| 285 | + networkEvents, |
| 286 | + links, |
| 287 | + CHILD_SPAN_COUNT, |
| 288 | + status, |
| 289 | + endTimestamp); |
| 290 | + |
| 291 | + Span span = handler.generateSpan(spanData); |
| 292 | + Map<String, AttributeValue> attributes = span.getAttributes().getAttributeMapMap(); |
| 293 | + |
| 294 | + assertThat(attributes).containsEntry("/http/host", toStringValue("host")); |
| 295 | + assertThat(attributes).containsEntry("/http/method", toStringValue("method")); |
| 296 | + assertThat(attributes).containsEntry("/http/path", toStringValue("path")); |
| 297 | + assertThat(attributes).containsEntry("/http/route", toStringValue("route")); |
| 298 | + assertThat(attributes).containsEntry("/http/user_agent", toStringValue("user_agent")); |
| 299 | + assertThat(attributes) |
| 300 | + .containsEntry("/http/status_code", AttributeValue.newBuilder().setIntValue(200L).build()); |
| 301 | + } |
| 302 | + |
| 303 | + private static AttributeValue toStringValue(String value) { |
| 304 | + return AttributeValue.newBuilder() |
| 305 | + .setStringValue( |
| 306 | + TruncatableString.newBuilder().setValue(value).setTruncatedByteCount(0).build()) |
| 307 | + .build(); |
| 308 | + } |
258 | 309 | } |
0 commit comments