Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional origin field #171

Closed
wants to merge 8 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions storage-xray-udp/RATIONALE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# storage-xray-udp rationale

14 changes: 14 additions & 0 deletions storage-xray-udp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
}

Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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 =
Expand Down