Skip to content

Commit

Permalink
format
Browse files Browse the repository at this point in the history
  • Loading branch information
Tianlin-Zhao committed Aug 13, 2020
1 parent 3887dc7 commit 1d47802
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 14 deletions.
3 changes: 2 additions & 1 deletion api/include/opentelemetry/trace/default_span.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,6 @@ class DefaultSpan : public Span
private:
SpanContext span_context_;
};

} // namespace trace
OPENTELEMETRY_END_NAMESPACE
OPENTELEMETRY_END_NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class HTTPTextFormat
nostd::string_view trace_type,
nostd::string_view trace_description);

// Returns the context that is stored in the HTTP header carrier with self defined rules.
// Returns the context that is stored in the HTTP header carrier with the getter as extractor.
virtual context::Context Extract(Getter get_from_carrier,
const T &carrier,
context::Context &context) noexcept = 0;
Expand All @@ -41,4 +41,4 @@ class HTTPTextFormat
};
} // namespace propagation
} // namespace trace
OPENTELEMETRY_END_NAMESPACE
OPENTELEMETRY_END_NAMESPACE
34 changes: 23 additions & 11 deletions api/include/opentelemetry/trace/propagation/http_trace_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,46 +92,58 @@ class HttpTraceContext : public HTTPTextFormat<T>

static TraceId GenerateTraceIdFromString(nostd::string_view trace_id)
{
const char *tid = trace_id.begin();
char *trc_id = trace_id.begin();
uint8_t buf[16];
int tmp;
for (int i = 0; i < 32; i++)
{
tmp = CharToInt(*trc_id);
if (tmp < 0)
return TraceId(0);
if (i % 2 == 0)
{
buf[i / 2] = CharToInt(*tid) * 16;
buf[i / 2] = tmp * 16;
}
else
{
buf[i / 2] += CharToInt(*tid);
buf[i / 2] += tmp;
}
tid++;
trc_id++;
}
return TraceId(buf);
}

static SpanId GenerateSpanIdFromString(nostd::string_view span_id)
{
const char *sid = span_id.begin();
char *spn_id = span_id.begin();
uint8_t buf[8];
int tmp;
for (int i = 0; i < 16; i++)
{
tmp = CharToInt(*spn_id);
if (tmp < 0)
return SpanId(0);
if (i % 2 == 0)
{
buf[i / 2] = CharToInt(*sid) * 16;
buf[i / 2] = tmp * 16;
}
else
{
buf[i / 2] += CharToInt(*sid);
buf[i / 2] += tmp;
}
sid++;
spn_id++;
}
return SpanId(buf);
return SpanId(spn_id);
}

static TraceFlags GenerateTraceFlagsFromString(nostd::string_view trace_flags)
{
uint8_t buf;
buf = CharToInt(trace_flags[0]) * 16 + CharToInt(trace_flags[1]);
int tmp1 = CharToInt(trace_flags[0]);
int tmp2 = CharToInt(trace_flags[1]);
if (tmp1 < 0 || tmp2 < 0)
return TraceFlags(0); // check for invalid char
buf = tmp1 * 16 + tmp2;
return TraceFlags(buf);
}

Expand All @@ -152,7 +164,7 @@ class HttpTraceContext : public HTTPTextFormat<T>
}
else
{
return 0;
return -1;
}
}

Expand Down

0 comments on commit 1d47802

Please sign in to comment.