Skip to content
Merged
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
12 changes: 6 additions & 6 deletions include/envoy/server/tracer_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,22 @@ class TracerFactory : public Config::TypedFactory {
~TracerFactory() override = default;

/**
* Create a particular HttpTracer implementation. If the implementation is unable to produce an
* HttpTracer with the provided parameters, it should throw an EnvoyException in the case of
* general error or a Json::Exception if the json configuration is erroneous. The returned
* Create a particular trace driver implementation. If the implementation is unable to produce
* a trace driver with the provided parameters, it should throw an EnvoyException in the case
* of general error or a Json::Exception if the json configuration is erroneous. The returned
* pointer should always be valid.
*
* NOTE: Due to the corner case of OpenCensus, who can only support a single tracing
* configuration per entire process, the returned HttpTracer instance is not guaranteed
* configuration per entire process, the returned Driver instance is not guaranteed
* to be unique.
* That is why the return type has been changed to std::shared_ptr<> instead of a more
* idiomatic std::unique_ptr<>.
*
* @param config supplies the proto configuration for the HttpTracer
* @param context supplies the factory context
*/
virtual Tracing::HttpTracerSharedPtr createHttpTracer(const Protobuf::Message& config,
TracerFactoryContext& context) PURE;
virtual Tracing::DriverSharedPtr createTracerDriver(const Protobuf::Message& config,
TracerFactoryContext& context) PURE;

std::string category() const override { return "envoy.tracers"; }
};
Expand Down
11 changes: 10 additions & 1 deletion include/envoy/tracing/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ envoy_cc_library(
name = "http_tracer_interface",
hdrs = ["http_tracer.h"],
deps = [
":trace_reason_interface",
":trace_driver_interface",
"//include/envoy/access_log:access_log_interface",
"//include/envoy/http:header_map_interface",
],
Expand All @@ -31,3 +31,12 @@ envoy_cc_library(
name = "trace_reason_interface",
hdrs = ["trace_reason.h"],
)

envoy_cc_library(
name = "trace_driver_interface",
hdrs = ["trace_driver.h"],
deps = [
":trace_reason_interface",
"//include/envoy/stream_info:stream_info_interface",
],
)
167 changes: 1 addition & 166 deletions include/envoy/tracing/http_tracer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,177 +7,12 @@
#include "envoy/access_log/access_log.h"
#include "envoy/common/pure.h"
#include "envoy/http/header_map.h"
#include "envoy/tracing/trace_driver.h"
#include "envoy/tracing/trace_reason.h"

namespace Envoy {
namespace Tracing {

class Span;
using SpanPtr = std::unique_ptr<Span>;

constexpr uint32_t DefaultMaxPathTagLength = 256;

enum class OperationName { Ingress, Egress };

/**
* The context for the custom tag to obtain the tag value.
*/
struct CustomTagContext {
const Http::RequestHeaderMap* request_headers;
const StreamInfo::StreamInfo& stream_info;
};

/**
* Tracing custom tag, with tag name and how it would be applied to the span.
*/
class CustomTag {
public:
virtual ~CustomTag() = default;

/**
* @return the tag name view.
*/
virtual absl::string_view tag() const PURE;

/**
* The way how to apply the custom tag to the span,
* generally obtain the tag value from the context and attached it to the span.
* @param span the active span.
* @param ctx the custom tag context.
*/
virtual void apply(Span& span, const CustomTagContext& ctx) const PURE;
};

using CustomTagConstSharedPtr = std::shared_ptr<const CustomTag>;
using CustomTagMap = absl::flat_hash_map<std::string, CustomTagConstSharedPtr>;

/**
* Tracing configuration, it carries additional data needed to populate the span.
*/
class Config {
public:
virtual ~Config() = default;

/**
* @return operation name for tracing, e.g., ingress.
*/
virtual OperationName operationName() const PURE;

/**
* @return custom tags to be attached to the active span.
*/
virtual const CustomTagMap* customTags() const PURE;

/**
* @return true if spans should be annotated with more detailed information.
*/
virtual bool verbose() const PURE;

/**
* @return the maximum length allowed for paths in the extracted HttpUrl tag.
*/
virtual uint32_t maxPathTagLength() const PURE;
};

/**
* Basic abstraction for span.
*/
class Span {
public:
virtual ~Span() = default;

/**
* Set the operation name.
* @param operation the operation name
*/
virtual void setOperation(absl::string_view operation) PURE;

/**
* Attach metadata to a Span, to be handled in an implementation-dependent fashion.
* @param name the name of the tag
* @param value the value to associate with the tag
*/
virtual void setTag(absl::string_view name, absl::string_view value) PURE;

/**
* Record an event associated with a span, to be handled in an implementation-dependent fashion.
* @param timestamp the time of the event.
* @param event the name of the event.
*/
virtual void log(SystemTime timestamp, const std::string& event) PURE;

/**
* Capture the final duration for this Span and carry out any work necessary to complete it.
* Once this method is called, the Span may be safely discarded.
*/
virtual void finishSpan() PURE;

/**
* Mutate the provided headers with the context necessary to propagate this
* (implementation-specific) trace.
* @param request_headers the headers to which propagation context will be added
*/
virtual void injectContext(Http::RequestHeaderMap& request_headers) PURE;

/**
* Create and start a child Span, with this Span as its parent in the trace.
* @param config the tracing configuration
* @param name operation name captured by the spawned child
* @param start_time initial start time for the operation captured by the child
*/
virtual SpanPtr spawnChild(const Config& config, const std::string& name,
SystemTime start_time) PURE;

/**
* This method overrides any previous sampling decision associated with the trace instance.
* If the sampled parameter is false, this span and any subsequent child spans
* are not reported to the tracing system.
* @param sampled whether the span and any subsequent child spans should be sampled
*/
virtual void setSampled(bool sampled) PURE;

/**
* Retrieve a key's value from the span's baggage.
* This baggage data could've been set by this span or any parent spans.
* @param key baggage key
* @return the baggage's value for the given input key
*/
virtual std::string getBaggage(absl::string_view key) PURE;

/**
* Set a key/value pair in the current span's baggage.
* All subsequent child spans will have access to this baggage.
* @param key baggage key
* @param key baggage value
*/
virtual void setBaggage(absl::string_view key, absl::string_view value) PURE;

/**
* Retrieve the trace ID associated with this span.
* The trace id may be generated for this span, propagated by parent spans, or
* not created yet.
* @return trace ID as a hex string
*/
virtual std::string getTraceIdAsHex() const PURE;
};

/**
* Tracing driver is responsible for span creation.
*/
class Driver {
public:
virtual ~Driver() = default;

/**
* Start driver specific span.
*/
virtual SpanPtr startSpan(const Config& config, Http::RequestHeaderMap& request_headers,
const std::string& operation_name, SystemTime start_time,
const Tracing::Decision tracing_decision) PURE;
};

using DriverPtr = std::unique_ptr<Driver>;

/**
* HttpTracer is responsible for handling traces and delegate actions to the
* corresponding drivers.
Expand Down
Loading