tag.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. package trace
  2. // Standard Span tags https://github.com/opentracing/specification/blob/master/semantic_conventions.md#span-tags-table
  3. const (
  4. // The software package, framework, library, or module that generated the associated Span.
  5. // E.g., "grpc", "django", "JDBI".
  6. // type string
  7. TagComponent = "component"
  8. // Database instance name.
  9. // E.g., In java, if the jdbc.url="jdbc:mysql://127.0.0.1:3306/customers", the instance name is "customers".
  10. // type string
  11. TagDBInstance = "db.instance"
  12. // A database statement for the given database type.
  13. // E.g., for db.type="sql", "SELECT * FROM wuser_table"; for db.type="redis", "SET mykey 'WuValue'".
  14. TagDBStatement = "db.statement"
  15. // Database type. For any SQL database, "sql". For others, the lower-case database category,
  16. // e.g. "cassandra", "hbase", or "redis".
  17. // type string
  18. TagDBType = "db.type"
  19. // Username for accessing database. E.g., "readonly_user" or "reporting_user"
  20. // type string
  21. TagDBUser = "db.user"
  22. // true if and only if the application considers the operation represented by the Span to have failed
  23. // type bool
  24. TagError = "error"
  25. // HTTP method of the request for the associated Span. E.g., "GET", "POST"
  26. // type string
  27. TagHTTPMethod = "http.method"
  28. // HTTP response status code for the associated Span. E.g., 200, 503, 404
  29. // type integer
  30. TagHTTPStatusCode = "http.status_code"
  31. // URL of the request being handled in this segment of the trace, in standard URI format.
  32. // E.g., "https://domain.net/path/to?resource=here"
  33. // type string
  34. TagHTTPURL = "http.url"
  35. // An address at which messages can be exchanged.
  36. // E.g. A Kafka record has an associated "topic name" that can be extracted by the instrumented producer or consumer and stored using this tag.
  37. // type string
  38. TagMessageBusDestination = "message_bus.destination"
  39. // Remote "address", suitable for use in a networking client library.
  40. // This may be a "ip:port", a bare "hostname", a FQDN, or even a JDBC substring like "mysql://prod-db:3306"
  41. // type string
  42. TagPeerAddress = "peer.address"
  43. // Remote hostname. E.g., "opentracing.io", "internal.dns.name"
  44. // type string
  45. TagPeerHostname = "peer.hostname"
  46. // Remote IPv4 address as a .-separated tuple. E.g., "127.0.0.1"
  47. // type string
  48. TagPeerIPv4 = "peer.ipv4"
  49. // Remote IPv6 address as a string of colon-separated 4-char hex tuples.
  50. // E.g., "2001:0db8:85a3:0000:0000:8a2e:0370:7334"
  51. // type string
  52. TagPeerIPv6 = "peer.ipv6"
  53. // Remote port. E.g., 80
  54. // type integer
  55. TagPeerPort = "peer.port"
  56. // Remote service name (for some unspecified definition of "service").
  57. // E.g., "elasticsearch", "a_custom_microservice", "memcache"
  58. // type string
  59. TagPeerService = "peer.service"
  60. // If greater than 0, a hint to the Tracer to do its best to capture the trace.
  61. // If 0, a hint to the trace to not-capture the trace. If absent, the Tracer should use its default sampling mechanism.
  62. // type string
  63. TagSamplingPriority = "sampling.priority"
  64. // Either "client" or "server" for the appropriate roles in an RPC,
  65. // and "producer" or "consumer" for the appropriate roles in a messaging scenario.
  66. // type string
  67. TagSpanKind = "span.kind"
  68. // legacy tag
  69. TagAnnotation = "legacy.annotation"
  70. TagAddress = "legacy.address"
  71. TagComment = "legacy.comment"
  72. )
  73. // Standard log tags
  74. const (
  75. // The type or "kind" of an error (only for event="error" logs). E.g., "Exception", "OSError"
  76. // type string
  77. LogErrorKind = "error.kind"
  78. // For languages that support such a thing (e.g., Java, Python),
  79. // the actual Throwable/Exception/Error object instance itself.
  80. // E.g., A java.lang.UnsupportedOperationException instance, a python exceptions.NameError instance
  81. // type string
  82. LogErrorObject = "error.object"
  83. // A stable identifier for some notable moment in the lifetime of a Span. For instance, a mutex lock acquisition or release or the sorts of lifetime events in a browser page load described in the Performance.timing specification. E.g., from Zipkin, "cs", "sr", "ss", or "cr". Or, more generally, "initialized" or "timed out". For errors, "error"
  84. // type string
  85. LogEvent = "event"
  86. // A concise, human-readable, one-line message explaining the event.
  87. // E.g., "Could not connect to backend", "Cache invalidation succeeded"
  88. // type string
  89. LogMessage = "message"
  90. // A stack trace in platform-conventional format; may or may not pertain to an error. E.g., "File \"example.py\", line 7, in \<module\>\ncaller()\nFile \"example.py\", line 5, in caller\ncallee()\nFile \"example.py\", line 2, in callee\nraise Exception(\"Yikes\")\n"
  91. // type string
  92. LogStack = "stack"
  93. )
  94. // Tag interface
  95. type Tag struct {
  96. Key string
  97. Value interface{}
  98. }
  99. // TagString new string tag.
  100. func TagString(key string, val string) Tag {
  101. return Tag{Key: key, Value: val}
  102. }
  103. // TagInt64 new int64 tag.
  104. func TagInt64(key string, val int64) Tag {
  105. return Tag{Key: key, Value: val}
  106. }
  107. // TagInt new int tag
  108. func TagInt(key string, val int) Tag {
  109. return Tag{Key: key, Value: val}
  110. }
  111. // TagBool new bool tag
  112. func TagBool(key string, val bool) Tag {
  113. return Tag{Key: key, Value: val}
  114. }
  115. // TagFloat64 new float64 tag
  116. func TagFloat64(key string, val float64) Tag {
  117. return Tag{Key: key, Value: val}
  118. }
  119. // TagFloat32 new float64 tag
  120. func TagFloat32(key string, val float32) Tag {
  121. return Tag{Key: key, Value: val}
  122. }
  123. // String new tag String.
  124. // NOTE: use TagString
  125. func String(key string, val string) Tag {
  126. return TagString(key, val)
  127. }
  128. // Int new tag Int.
  129. // NOTE: use TagInt
  130. func Int(key string, val int) Tag {
  131. return TagInt(key, val)
  132. }
  133. // Bool new tagBool
  134. // NOTE: use TagBool
  135. func Bool(key string, val bool) Tag {
  136. return TagBool(key, val)
  137. }
  138. // Log new log.
  139. func Log(key string, val string) LogField {
  140. return LogField{Key: key, Value: val}
  141. }
  142. // LogField LogField
  143. type LogField struct {
  144. Key string
  145. Value string
  146. }