You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

120 line
3.5 KiB

  1. // Copyright 2017, OpenCensus Authors
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. package trace
  15. import (
  16. "fmt"
  17. "time"
  18. )
  19. type (
  20. // TraceID is a 16-byte identifier for a set of spans.
  21. TraceID [16]byte
  22. // SpanID is an 8-byte identifier for a single span.
  23. SpanID [8]byte
  24. )
  25. func (t TraceID) String() string {
  26. return fmt.Sprintf("%02x", t[:])
  27. }
  28. func (s SpanID) String() string {
  29. return fmt.Sprintf("%02x", s[:])
  30. }
  31. // Annotation represents a text annotation with a set of attributes and a timestamp.
  32. type Annotation struct {
  33. Time time.Time
  34. Message string
  35. Attributes map[string]interface{}
  36. }
  37. // Attribute represents a key-value pair on a span, link or annotation.
  38. // Construct with one of: BoolAttribute, Int64Attribute, or StringAttribute.
  39. type Attribute struct {
  40. key string
  41. value interface{}
  42. }
  43. // BoolAttribute returns a bool-valued attribute.
  44. func BoolAttribute(key string, value bool) Attribute {
  45. return Attribute{key: key, value: value}
  46. }
  47. // Int64Attribute returns an int64-valued attribute.
  48. func Int64Attribute(key string, value int64) Attribute {
  49. return Attribute{key: key, value: value}
  50. }
  51. // Float64Attribute returns a float64-valued attribute.
  52. func Float64Attribute(key string, value float64) Attribute {
  53. return Attribute{key: key, value: value}
  54. }
  55. // StringAttribute returns a string-valued attribute.
  56. func StringAttribute(key string, value string) Attribute {
  57. return Attribute{key: key, value: value}
  58. }
  59. // LinkType specifies the relationship between the span that had the link
  60. // added, and the linked span.
  61. type LinkType int32
  62. // LinkType values.
  63. const (
  64. LinkTypeUnspecified LinkType = iota // The relationship of the two spans is unknown.
  65. LinkTypeChild // The linked span is a child of the current span.
  66. LinkTypeParent // The linked span is the parent of the current span.
  67. )
  68. // Link represents a reference from one span to another span.
  69. type Link struct {
  70. TraceID TraceID
  71. SpanID SpanID
  72. Type LinkType
  73. // Attributes is a set of attributes on the link.
  74. Attributes map[string]interface{}
  75. }
  76. // MessageEventType specifies the type of message event.
  77. type MessageEventType int32
  78. // MessageEventType values.
  79. const (
  80. MessageEventTypeUnspecified MessageEventType = iota // Unknown event type.
  81. MessageEventTypeSent // Indicates a sent RPC message.
  82. MessageEventTypeRecv // Indicates a received RPC message.
  83. )
  84. // MessageEvent represents an event describing a message sent or received on the network.
  85. type MessageEvent struct {
  86. Time time.Time
  87. EventType MessageEventType
  88. MessageID int64
  89. UncompressedByteSize int64
  90. CompressedByteSize int64
  91. }
  92. // Status is the status of a Span.
  93. type Status struct {
  94. // Code is a status code. Zero indicates success.
  95. //
  96. // If Code will be propagated to Google APIs, it ideally should be a value from
  97. // https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto .
  98. Code int32
  99. Message string
  100. }