@@ -132,8 +132,8 @@ class Endpoint
132132};
133133
134134struct Tracer ;
135-
136135class CachedTracer ;
136+ class Span ;
137137
138138/* *
139139* \brief Associates an event that explains latency with a timestamp.
@@ -142,10 +142,13 @@ class CachedTracer;
142142*/
143143class Annotation
144144{
145+ Span &m_span;
145146 ::Annotation &m_annotation;
146147
147148 public:
148- Annotation (::Annotation &annotation) : m_annotation(annotation) {}
149+ Annotation (Span &span, ::Annotation &annotation) : m_span(span), m_annotation(annotation) {}
150+
151+ Span &span (void ) { return m_span; }
149152
150153 /* *
151154 * \brief Microseconds from epoch.
@@ -390,10 +393,13 @@ struct TraceKeys
390393*/
391394class BinaryAnnotation
392395{
396+ Span &m_span;
393397 ::BinaryAnnotation &m_annotation;
394398
395399 public:
396- BinaryAnnotation (::BinaryAnnotation &annotation) : m_annotation(annotation) {}
400+ BinaryAnnotation (Span &span, ::BinaryAnnotation &annotation) : m_span(span), m_annotation(annotation) {}
401+
402+ Span &span (void ) { return m_span; }
397403
398404 /* *
399405 * \brief The thrift type of value, most often AnnotationType#STRING.
@@ -906,112 +912,94 @@ class Span
906912 };
907913};
908914
909- static inline Span &operator <<(Span &span, const std::string &value)
910- {
911- span.annotate (value);
912-
913- return span;
914- }
915-
916915namespace __impl
917916{
918917
919918template <typename K, typename V>
920919struct __annotation
921920{
922- static void apply (Span &span, const std::pair<K, V> &value)
923- {
924- span.annotate (value.first , value.second );
925- }
926-
927- static void apply (Span &span, const boost::tuple<K, V, Endpoint *> &value)
928- {
929- span.annotate (boost::get<0 >(value), boost::get<1 >(value), boost::get<2 >(value));
930- }
931- };
932-
933- template <>
934- struct __annotation <const char *, Endpoint *>
935- {
936- static void apply (Span &span, const std::pair<const char *, Endpoint *> &value)
921+ static BinaryAnnotation apply (Span &span, const std::pair<K, V> &value)
937922 {
938- ::Annotation annotation;
939-
940- annotation.__set_timestamp (Span::now ().count ());
941- annotation.__set_value (value.first );
942-
943- if (value.second )
944- {
945- annotation.__set_host (value.second ->host ());
946- }
947-
948- span.message ().annotations .push_back (annotation);
923+ return span.annotate (value.first , value.second );
949924 }
950- };
951925
952- template <>
953- struct __annotation <std::string, Endpoint *>
954- {
955- static void apply (Span &span, const std::pair<std::string, Endpoint *> &value)
926+ static BinaryAnnotation apply (Span &span, const boost::tuple<K, V, Endpoint *> &value)
956927 {
957- ::Annotation annotation;
958-
959- annotation.__set_timestamp (Span::now ().count ());
960- annotation.__set_value (value.first );
961-
962- if (value.second )
963- {
964- annotation.__set_host (value.second ->host ());
965- }
966-
967- span.message ().annotations .push_back (annotation);
928+ return span.annotate (boost::get<0 >(value), boost::get<1 >(value), boost::get<2 >(value));
968929 }
969930};
970931
971932template <typename K>
972933struct __annotation <K, const char *>
973934{
974- static void apply (Span &span, const std::pair<K, const char *> &value)
935+ static BinaryAnnotation apply (Span &span, const std::pair<K, const char *> &value)
975936 {
976- span.annotate (value.first , value.second );
937+ return span.annotate (value.first , value.second );
977938 }
978939
979- static void apply (Span &span, const boost::tuple<K, const char *, Endpoint *> &value)
940+ static BinaryAnnotation apply (Span &span, const boost::tuple<K, const char *, Endpoint *> &value)
980941 {
981- span.annotate (boost::get<0 >(value), boost::get<1 >(value), -1 , boost::get<2 >(value));
942+ return span.annotate (boost::get<0 >(value), boost::get<1 >(value), -1 , boost::get<2 >(value));
982943 }
983944};
984945
985946template <typename K>
986947struct __annotation <K, const wchar_t *>
987948{
988- static void apply (Span &span, const std::pair<K, const wchar_t *> &value)
949+ static BinaryAnnotation apply (Span &span, const std::pair<K, const wchar_t *> &value)
989950 {
990- span.annotate (value.first , value.second );
951+ return span.annotate (value.first , value.second );
991952 }
992953
993- static void apply (Span &span, const boost::tuple<K, const wchar_t *, Endpoint *> &value)
954+ static BinaryAnnotation apply (Span &span, const boost::tuple<K, const wchar_t *, Endpoint *> &value)
994955 {
995- span.annotate (boost::get<0 >(value), boost::get<1 >(value), -1 , boost::get<2 >(value));
956+ return span.annotate (boost::get<0 >(value), boost::get<1 >(value), -1 , boost::get<2 >(value));
996957 }
997958};
998959
999960} // namespace __impl
1000961
1001- template <typename K, typename V>
1002- Span &operator <<(Span &span, const std::pair<K, V> &value)
962+ static inline Annotation operator <<(Span &span, const std::string &value)
963+ {
964+ return span.annotate (value);
965+ }
966+
967+ static inline Annotation operator <<(Annotation annotation, const std::string &value)
968+ {
969+ return annotation.span ().annotate (value);
970+ }
971+
972+ static inline Annotation operator <<(BinaryAnnotation annotation, const std::string &value)
1003973{
1004- __impl::__annotation<K, V>::apply (span, value);
974+ return annotation.span ().annotate (value);
975+ }
976+
977+ static inline Span &operator <<(Annotation annotation, const zipkin::Endpoint &endpoint)
978+ {
979+ return annotation.with_endpoint (endpoint).span ();
980+ }
981+
982+ static inline Span &operator <<(BinaryAnnotation annotation, const zipkin::Endpoint &endpoint)
983+ {
984+ return annotation.with_endpoint (endpoint).span ();
985+ }
1005986
1006- return span;
987+ template <typename K, typename V>
988+ BinaryAnnotation operator <<(Span &span, const std::pair<K, V> &value)
989+ {
990+ return __impl::__annotation<K, V>::apply (span, value);
1007991}
1008992
1009993template <typename K, typename V>
1010- Span & operator <<(Span &span , const boost::tuple <K, V, Endpoint * > &value)
994+ BinaryAnnotation operator <<(Annotation annotation , const std::pair <K, V> &value)
1011995{
1012- __impl::__annotation<K, V>::apply (span, value);
996+ return __impl::__annotation<K, V>::apply (annotation.span (), value);
997+ }
1013998
1014- return span;
999+ template <typename K, typename V>
1000+ BinaryAnnotation operator <<(BinaryAnnotation annotation, const std::pair<K, V> &value)
1001+ {
1002+ return __impl::__annotation<K, V>::apply (annotation.span (), value);
10151003}
10161004
10171005class CachedSpan : public Span
@@ -1143,7 +1131,7 @@ inline BinaryAnnotation Span::annotate(const std::string &key, const T &value, c
11431131
11441132 m_span.binary_annotations .push_back (annotation);
11451133
1146- return BinaryAnnotation (m_span.binary_annotations .back ());
1134+ return BinaryAnnotation (* this , m_span.binary_annotations .back ());
11471135}
11481136
11491137namespace base64
0 commit comments