diff --git a/storage-xray-udp/RATIONALE.md b/storage-xray-udp/RATIONALE.md new file mode 100644 index 00000000..11ff3691 --- /dev/null +++ b/storage-xray-udp/RATIONALE.md @@ -0,0 +1,2 @@ +# storage-xray-udp rationale + diff --git a/storage-xray-udp/README.md b/storage-xray-udp/README.md index 9794a74b..3add520b 100644 --- a/storage-xray-udp/README.md +++ b/storage-xray-udp/README.md @@ -4,3 +4,17 @@ Encoding and wire protocol for sending Zipkin spans to AWS X-Ray. See [reporter-xray-udp](../reporter-xray-udp) for instructions on setting up X-Ray reporting for an application. + +## Overview +This storage module performs three activites: + 1. Receives incoming zipkin spans + 2. Encodes received zipkin spans to X-Ray compatible segments + 3. Forwards the encoded X-Ray segments to a X-Ray daemon endpoint + +The encoder is implemented by `zipkin2.storage.xray_udp.UDPMessageEncoder` class. + +### Field Mappings + +| Name | Source | Destination | Mandatory | Transformation | Reference | +|------|--------|-------------|-----------|----------------|-----------| +| Origin | `span.tags['aws.origin']` | `segment.origin` | No | Simple value mapped | [**Segment fields**](https://docs.aws.amazon.com/xray/latest/devguide/xray-api-segmentdocuments.html#api-segmentdocuments-fields) > **Optional Segment Fields** > `origin` | \ No newline at end of file diff --git a/storage-xray-udp/src/main/java/zipkin2/storage/xray_udp/UDPMessageEncoder.java b/storage-xray-udp/src/main/java/zipkin2/storage/xray_udp/UDPMessageEncoder.java index de705734..f367153f 100644 --- a/storage-xray-udp/src/main/java/zipkin2/storage/xray_udp/UDPMessageEncoder.java +++ b/storage-xray-udp/src/main/java/zipkin2/storage/xray_udp/UDPMessageEncoder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 The OpenZipkin Authors + * Copyright 2016-2020 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -110,6 +110,8 @@ static void writeJson(Span span, Buffer buffer) throws IOException { // aws.ec2 section String ec2AvailabilityZone = null, ec2InstanceId = null; + // aws.origin section + String xrayOrigin = null; // cause section String causeWorkingDirectory = null, causeExceptions = null; boolean http = false, sql = false, aws = false, cause = false; @@ -185,6 +187,9 @@ static void writeJson(Span span, Buffer buffer) throws IOException { case "aws.ec2.instance_id": ec2InstanceId = entry.getValue(); continue; + case "aws.origin": + xrayOrigin = entry.getValue(); + continue; } } @@ -273,6 +278,7 @@ static void writeJson(Span span, Buffer buffer) throws IOException { writer.endObject(); } writer.endObject(); + if (xrayOrigin != null) writer.name("origin").value(xrayOrigin); } if (cause) { diff --git a/storage-xray-udp/src/test/java/zipkin2/storage/xray_udp/UDPMessageEncoderTest.java b/storage-xray-udp/src/test/java/zipkin2/storage/xray_udp/UDPMessageEncoderTest.java index 1b2910cb..bd37b308 100644 --- a/storage-xray-udp/src/test/java/zipkin2/storage/xray_udp/UDPMessageEncoderTest.java +++ b/storage-xray-udp/src/test/java/zipkin2/storage/xray_udp/UDPMessageEncoderTest.java @@ -1,5 +1,5 @@ /* - * Copyright 2016-2019 The OpenZipkin Authors + * Copyright 2016-2020 The OpenZipkin Authors * * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except * in compliance with the License. You may obtain a copy of the License at @@ -43,6 +43,30 @@ public void writeJson_server_isSegment() throws Exception { "{\"trace_id\":\"1-12345678-90abcdef1234567890abcdef\",\"id\":\"1234567890abcdef\"}"); } + @Test + public void writeJson_origin_no_default() throws Exception { + Span span = + serverSpan + .toBuilder() + .build(); + + String json = writeJson(span); + assertThat(readString(json, "origin")).isNull(); + } + + @Test + public void writeJson_origin_custom() throws Exception { + Span span = + serverSpan + .toBuilder() + .putTag("aws.origin", "AWS::EC2::Instance") + .build(); + + String json = writeJson(span); + assertThat(readString(json, "origin")).isEqualTo("AWS::EC2::Instance"); + assertThat(readString(json, "annotations.aws_origin")).isNull(); + } + @Test public void writeJson_server_localEndpointIsName() throws Exception { Span span =