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

Commit fe2f91a

Browse files
authored
Fix ocagent trace exporter. (#390)
* Trace/Span IDs need to be binary, not hex encoded. * Don't set parent_span_id on root spans.
1 parent 1bbde06 commit fe2f91a

5 files changed

Lines changed: 20 additions & 5 deletions

File tree

opencensus/exporters/trace/ocagent/internal/ocagent_exporter.cc

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,16 @@ void ConvertSpans(
208208
auto to_span = request->add_spans();
209209

210210
// 1. trace_id
211-
to_span->set_trace_id(from_span.context().trace_id().ToHex());
211+
to_span->set_trace_id(from_span.context().trace_id().Value(),
212+
::opencensus::trace::TraceId::kSize);
212213
// 2. span_id
213-
to_span->set_span_id(from_span.context().span_id().ToHex());
214+
to_span->set_span_id(from_span.context().span_id().Value(),
215+
::opencensus::trace::SpanId::kSize);
214216
// 3. parent_span_id
215-
to_span->set_parent_span_id(from_span.parent_span_id().ToHex());
217+
if (from_span.parent_span_id().IsValid()) {
218+
to_span->set_parent_span_id(from_span.parent_span_id().Value(),
219+
::opencensus::trace::SpanId::kSize);
220+
}
216221
// 4. name
217222
SetTruncatableString(from_span.name(), kDisplayNameStringLen,
218223
to_span->mutable_name());
@@ -224,7 +229,7 @@ void ConvertSpans(
224229
// 7. Export Attributes
225230
ConvertAttributes(from_span, to_span);
226231

227-
// 8. stack_trace
232+
// 8. stack_trace (unsupported)
228233

229234
// 9. Export Time Events.
230235
ConvertTimeEvents(from_span, to_span);
@@ -241,7 +246,7 @@ void ConvertSpans(
241246
to_span->mutable_same_process_as_parent_span()->set_value(
242247
!from_span.has_remote_parent());
243248

244-
// 13. child_span_count
249+
// 13. child_span_count (optional)
245250

246251
// 14. span kind
247252

opencensus/trace/internal/span_id.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ std::string SpanId::ToHex() const {
3030
absl::string_view(reinterpret_cast<const char *>(rep_), kSize));
3131
}
3232

33+
const void *SpanId::Value() const { return rep_; }
34+
3335
bool SpanId::operator==(const SpanId &that) const {
3436
return memcmp(rep_, that.rep_, kSize) == 0;
3537
}

opencensus/trace/internal/trace_id.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ std::string TraceId::ToHex() const {
3030
absl::string_view(reinterpret_cast<const char *>(rep_), kSize));
3131
}
3232

33+
const void *TraceId::Value() const { return rep_; }
34+
3335
bool TraceId::operator==(const TraceId &that) const {
3436
return memcmp(rep_, that.rep_, kSize) == 0;
3537
}

opencensus/trace/span_id.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class SpanId final {
3737
// Returns a 16-char hex string of the SpanId value.
3838
std::string ToHex() const;
3939

40+
// Returns a pointer to the opaque value.
41+
const void* Value() const;
42+
4043
bool operator==(const SpanId& that) const;
4144

4245
// Returns false if the SpanId is all zeros.

opencensus/trace/trace_id.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ class TraceId final {
3737
// Returns a 32-char hex string of the TraceId value.
3838
std::string ToHex() const;
3939

40+
// Returns a pointer to the opaque value.
41+
const void* Value() const;
42+
4043
bool operator==(const TraceId& that) const;
4144

4245
// Returns false if the TraceId is all zeros.

0 commit comments

Comments
 (0)