@@ -132,8 +132,8 @@ class Endpoint
132
132
};
133
133
134
134
struct Tracer ;
135
-
136
135
class CachedTracer ;
136
+ class Span ;
137
137
138
138
/* *
139
139
* \brief Associates an event that explains latency with a timestamp.
@@ -142,10 +142,13 @@ class CachedTracer;
142
142
*/
143
143
class Annotation
144
144
{
145
+ Span &m_span;
145
146
::Annotation &m_annotation;
146
147
147
148
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; }
149
152
150
153
/* *
151
154
* \brief Microseconds from epoch.
@@ -390,10 +393,13 @@ struct TraceKeys
390
393
*/
391
394
class BinaryAnnotation
392
395
{
396
+ Span &m_span;
393
397
::BinaryAnnotation &m_annotation;
394
398
395
399
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; }
397
403
398
404
/* *
399
405
* \brief The thrift type of value, most often AnnotationType#STRING.
@@ -906,112 +912,94 @@ class Span
906
912
};
907
913
};
908
914
909
- static inline Span &operator <<(Span &span, const std::string &value)
910
- {
911
- span.annotate (value);
912
-
913
- return span;
914
- }
915
-
916
915
namespace __impl
917
916
{
918
917
919
918
template <typename K, typename V>
920
919
struct __annotation
921
920
{
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)
937
922
{
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 );
949
924
}
950
- };
951
925
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)
956
927
{
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));
968
929
}
969
930
};
970
931
971
932
template <typename K>
972
933
struct __annotation <K, const char *>
973
934
{
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)
975
936
{
976
- span.annotate (value.first , value.second );
937
+ return span.annotate (value.first , value.second );
977
938
}
978
939
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)
980
941
{
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));
982
943
}
983
944
};
984
945
985
946
template <typename K>
986
947
struct __annotation <K, const wchar_t *>
987
948
{
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)
989
950
{
990
- span.annotate (value.first , value.second );
951
+ return span.annotate (value.first , value.second );
991
952
}
992
953
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)
994
955
{
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));
996
957
}
997
958
};
998
959
999
960
} // namespace __impl
1000
961
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)
1003
973
{
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
+ }
1005
986
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);
1007
991
}
1008
992
1009
993
template <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)
1011
995
{
1012
- __impl::__annotation<K, V>::apply (span, value);
996
+ return __impl::__annotation<K, V>::apply (annotation.span (), value);
997
+ }
1013
998
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);
1015
1003
}
1016
1004
1017
1005
class CachedSpan : public Span
@@ -1143,7 +1131,7 @@ inline BinaryAnnotation Span::annotate(const std::string &key, const T &value, c
1143
1131
1144
1132
m_span.binary_annotations .push_back (annotation);
1145
1133
1146
- return BinaryAnnotation (m_span.binary_annotations .back ());
1134
+ return BinaryAnnotation (* this , m_span.binary_annotations .back ());
1147
1135
}
1148
1136
1149
1137
namespace base64
0 commit comments