Skip to content

Commit 5de26a4

Browse files
authored
Merge pull request #35 from lightstep/jmacd/relationship_ref
Encode span relationships in the appropriate Span field.
2 parents f540a85 + e13929a commit 5de26a4

File tree

3 files changed

+16
-18
lines changed

3 files changed

+16
-18
lines changed

src/c++11/impl.cc

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,15 +231,17 @@ void SpanImpl::FinishSpan(SpanFinishOptions opts) {
231231
auto tags = span.mutable_tags();
232232

233233
if (ref_.valid()) {
234-
// Note: Converting span_id to a hex string here is necessary
235-
// because the Proto->Thrift conversion does not know to format
236-
// int-valued tags as hex-valued, yet the string value for
237-
// parent_span_guid is interpreted as a hex value downstream.
238-
//
239-
// TODO: The protocol supports encoding relationships directly.
240-
// switch to the native representation after validating the
241-
// feature in the collector.
242-
*tags->Add() = util::make_kv(ParentSpanGUIDKey, uint64ToHex(ref_.referenced().span_id()));
234+
auto refs = span.mutable_references();
235+
auto ref = refs->Add();
236+
ref->mutable_span_context()->set_span_id(ref_.referenced().span_id());
237+
switch (ref_.type()) {
238+
case FollowsFromRef:
239+
ref->set_relationship(collector::Reference::FOLLOWS_FROM);
240+
break;
241+
default:
242+
ref->set_relationship(collector::Reference::CHILD_OF);
243+
break;
244+
}
243245
}
244246

245247
{

src/c++11/lightstep/propagation.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ class SpanReference : public SpanStartOption {
109109
// This is a no-op if the referenced context is not valid.
110110
virtual void Apply(SpanImpl *span) const override;
111111

112+
// Return the relationship type of this reference.
113+
SpanReferenceType type() const { return type_; }
114+
112115
private:
113116
SpanReferenceType type_;
114117
SpanContext referenced_;

test/c++11/tracer_test.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ int main() {
3434

3535
TracerOptions topts;
3636

37-
topts.access_token = "DEVELOPMENT_TOKEN_jmacd";
37+
topts.access_token = "3e5170e56cc4f4b2c94695a13ddf23d1";
3838
topts.collector_host = "localhost";
39-
topts.collector_port = 9998;
39+
topts.collector_port = 9997;
4040
topts.collector_encryption = "";
4141

4242
BasicRecorderOptions bopts;
@@ -56,13 +56,6 @@ int main() {
5656
auto cspan = Tracer::Global().StartSpan("span/child", { ChildOf(parent) });
5757
cspan.Finish();
5858

59-
auto child = cspan.context();
60-
61-
// if (child.parent_span_id() == 0 ||
62-
// child.parent_span_id() != parent.span_id()) {
63-
// throw error("parent/child span_id mismatch");
64-
// }
65-
6659
Tracer::Global().impl()->Flush();
6760
} catch (std::exception &e) {
6861
std::cerr << "Exception! " << e.what() << std::endl;

0 commit comments

Comments
 (0)