Code refactoring for bpa operator
[icn.git] / cmd / bpa-operator / vendor / go.opencensus.io / trace / basetypes.go
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
15 package trace
16
17 import (
18         "fmt"
19         "time"
20 )
21
22 type (
23         // TraceID is a 16-byte identifier for a set of spans.
24         TraceID [16]byte
25
26         // SpanID is an 8-byte identifier for a single span.
27         SpanID [8]byte
28 )
29
30 func (t TraceID) String() string {
31         return fmt.Sprintf("%02x", t[:])
32 }
33
34 func (s SpanID) String() string {
35         return fmt.Sprintf("%02x", s[:])
36 }
37
38 // Annotation represents a text annotation with a set of attributes and a timestamp.
39 type Annotation struct {
40         Time       time.Time
41         Message    string
42         Attributes map[string]interface{}
43 }
44
45 // Attribute represents a key-value pair on a span, link or annotation.
46 // Construct with one of: BoolAttribute, Int64Attribute, or StringAttribute.
47 type Attribute struct {
48         key   string
49         value interface{}
50 }
51
52 // BoolAttribute returns a bool-valued attribute.
53 func BoolAttribute(key string, value bool) Attribute {
54         return Attribute{key: key, value: value}
55 }
56
57 // Int64Attribute returns an int64-valued attribute.
58 func Int64Attribute(key string, value int64) Attribute {
59         return Attribute{key: key, value: value}
60 }
61
62 // Float64Attribute returns a float64-valued attribute.
63 func Float64Attribute(key string, value float64) Attribute {
64         return Attribute{key: key, value: value}
65 }
66
67 // StringAttribute returns a string-valued attribute.
68 func StringAttribute(key string, value string) Attribute {
69         return Attribute{key: key, value: value}
70 }
71
72 // LinkType specifies the relationship between the span that had the link
73 // added, and the linked span.
74 type LinkType int32
75
76 // LinkType values.
77 const (
78         LinkTypeUnspecified LinkType = iota // The relationship of the two spans is unknown.
79         LinkTypeChild                       // The linked span is a child of the current span.
80         LinkTypeParent                      // The linked span is the parent of the current span.
81 )
82
83 // Link represents a reference from one span to another span.
84 type Link struct {
85         TraceID TraceID
86         SpanID  SpanID
87         Type    LinkType
88         // Attributes is a set of attributes on the link.
89         Attributes map[string]interface{}
90 }
91
92 // MessageEventType specifies the type of message event.
93 type MessageEventType int32
94
95 // MessageEventType values.
96 const (
97         MessageEventTypeUnspecified MessageEventType = iota // Unknown event type.
98         MessageEventTypeSent                                // Indicates a sent RPC message.
99         MessageEventTypeRecv                                // Indicates a received RPC message.
100 )
101
102 // MessageEvent represents an event describing a message sent or received on the network.
103 type MessageEvent struct {
104         Time                 time.Time
105         EventType            MessageEventType
106         MessageID            int64
107         UncompressedByteSize int64
108         CompressedByteSize   int64
109 }
110
111 // Status is the status of a Span.
112 type Status struct {
113         // Code is a status code.  Zero indicates success.
114         //
115         // If Code will be propagated to Google APIs, it ideally should be a value from
116         // https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto .
117         Code    int32
118         Message string
119 }