forked from open-telemetry/opentelemetry-specification
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Http Trace Context (open-telemetry#143)
- Loading branch information
1 parent
eb04081
commit 09983ab
Showing
17 changed files
with
634 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#pragma once | ||
#include "opentelemetry/common/attribute_value.h" | ||
#include "opentelemetry/trace/canonical_code.h" | ||
#include "opentelemetry/trace/span.h" | ||
#include "opentelemetry/trace/span_context.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace trace | ||
{ | ||
class DefaultSpan : public Span | ||
{ | ||
public: | ||
// Returns an invalid span. | ||
static DefaultSpan GetInvalid() { return DefaultSpan(SpanContext::GetInvalid()); } | ||
|
||
trace::SpanContext GetContext() const noexcept { return span_context_; } | ||
|
||
bool IsRecording() const noexcept { return false; } | ||
|
||
void SetAttribute(nostd::string_view key, const common::AttributeValue &value) noexcept {} | ||
|
||
void AddEvent(nostd::string_view name) noexcept {} | ||
|
||
void AddEvent(nostd::string_view name, core::SystemTimestamp timestamp) noexcept {} | ||
|
||
void AddEvent(nostd::string_view name, | ||
core::SystemTimestamp timestamp, | ||
const KeyValueIterable &attributes) noexcept | ||
{} | ||
|
||
void AddEvent(nostd::string_view name, const KeyValueIterable &attributes) noexcept | ||
{ | ||
this->AddEvent(name, std::chrono::system_clock::now(), attributes); | ||
} | ||
|
||
void SetStatus(CanonicalCode status, nostd::string_view description) noexcept {} | ||
|
||
void UpdateName(nostd::string_view name) noexcept {} | ||
|
||
void End(const EndSpanOptions &options = {}) noexcept {} | ||
|
||
nostd::string_view ToString() { return "DefaultSpan"; } | ||
|
||
void SetToken(nostd::unique_ptr<context::Token> &&default_token) noexcept {} | ||
|
||
DefaultSpan() = default; | ||
|
||
DefaultSpan(SpanContext span_context) : span_context_(span_context) {} | ||
|
||
// movable and copiable | ||
DefaultSpan(DefaultSpan &&spn) : span_context_(spn.GetContext()) {} | ||
DefaultSpan(const DefaultSpan &spn) : span_context_(spn.GetContext()) {} | ||
|
||
private: | ||
SpanContext span_context_; | ||
}; | ||
|
||
} // namespace trace | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#pragma once | ||
#include "opentelemetry/nostd/unique_ptr.h" | ||
#include "opentelemetry/trace/default_span.h" | ||
#include "opentelemetry/trace/span.h" | ||
#include "opentelemetry/trace/tracer.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace trace | ||
{ | ||
class DefaultTracer : public Tracer | ||
{ | ||
public: | ||
~DefaultTracer() = default; | ||
|
||
/** | ||
* Starts a span. | ||
* | ||
* Optionally sets attributes at Span creation from the given key/value pairs. | ||
* | ||
* Attributes will be processed in order, previous attributes with the same | ||
* key will be overwritten. | ||
*/ | ||
nostd::unique_ptr<Span> StartSpan(nostd::string_view name, | ||
const KeyValueIterable &attributes, | ||
const StartSpanOptions &options = {}) override noexcept | ||
{ | ||
return nostd::unique_ptr<Span>(new DefaultSpan::GetInvalid()); | ||
} | ||
|
||
void ForceFlushWithMicroseconds(uint64_t timeout) override noexcept {} | ||
|
||
void CloseWithMicroseconds(uint64_t timeout) override noexcept {} | ||
}; | ||
} // namespace trace | ||
OPENTELEMETRY_END_NAMESPACE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
43 changes: 43 additions & 0 deletions
43
api/include/opentelemetry/trace/propagation/http_text_format.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include "opentelemetry/context/context.h" | ||
#include "opentelemetry/nostd/string_view.h" | ||
#include "opentelemetry/version.h" | ||
|
||
OPENTELEMETRY_BEGIN_NAMESPACE | ||
namespace trace | ||
{ | ||
namespace propagation | ||
{ | ||
|
||
// The HTTPTextFormat class provides an interface that enables extracting and injecting | ||
// context into headers of HTTP requests. HTTP frameworks and clients | ||
// can integrate with HTTPTextFormat by providing the object containing the | ||
// headers, and a getter and setter function for the extraction and | ||
// injection of values, respectively. | ||
template <typename T> | ||
class HTTPTextFormat | ||
{ | ||
public: | ||
// Rules that manages how context will be extracted from carrier. | ||
using Getter = nostd::string_view (*)(const T &carrier, nostd::string_view trace_type); | ||
|
||
// Rules that manages how context will be injected to carrier. | ||
using Setter = void (*)(T &carrier, | ||
nostd::string_view trace_type, | ||
nostd::string_view trace_description); | ||
|
||
// 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; | ||
|
||
// Sets the context for a HTTP header carrier with self defined rules. | ||
virtual void Inject(Setter set_from_carrier, | ||
T &carrier, | ||
const context::Context &context) noexcept = 0; | ||
}; | ||
} // namespace propagation | ||
} // namespace trace | ||
OPENTELEMETRY_END_NAMESPACE |
Oops, something went wrong.