...

Source file src/go.opencensus.io/trace/basetypes.go

Documentation: go.opencensus.io/trace

     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  // Key returns the attribute's key
    53  func (a *Attribute) Key() string {
    54  	return a.key
    55  }
    56  
    57  // Value returns the attribute's value
    58  func (a *Attribute) Value() interface{} {
    59  	return a.value
    60  }
    61  
    62  // BoolAttribute returns a bool-valued attribute.
    63  func BoolAttribute(key string, value bool) Attribute {
    64  	return Attribute{key: key, value: value}
    65  }
    66  
    67  // Int64Attribute returns an int64-valued attribute.
    68  func Int64Attribute(key string, value int64) Attribute {
    69  	return Attribute{key: key, value: value}
    70  }
    71  
    72  // Float64Attribute returns a float64-valued attribute.
    73  func Float64Attribute(key string, value float64) Attribute {
    74  	return Attribute{key: key, value: value}
    75  }
    76  
    77  // StringAttribute returns a string-valued attribute.
    78  func StringAttribute(key string, value string) Attribute {
    79  	return Attribute{key: key, value: value}
    80  }
    81  
    82  // LinkType specifies the relationship between the span that had the link
    83  // added, and the linked span.
    84  type LinkType int32
    85  
    86  // LinkType values.
    87  const (
    88  	LinkTypeUnspecified LinkType = iota // The relationship of the two spans is unknown.
    89  	LinkTypeChild                       // The linked span is a child of the current span.
    90  	LinkTypeParent                      // The linked span is the parent of the current span.
    91  )
    92  
    93  // Link represents a reference from one span to another span.
    94  type Link struct {
    95  	TraceID TraceID
    96  	SpanID  SpanID
    97  	Type    LinkType
    98  	// Attributes is a set of attributes on the link.
    99  	Attributes map[string]interface{}
   100  }
   101  
   102  // MessageEventType specifies the type of message event.
   103  type MessageEventType int32
   104  
   105  // MessageEventType values.
   106  const (
   107  	MessageEventTypeUnspecified MessageEventType = iota // Unknown event type.
   108  	MessageEventTypeSent                                // Indicates a sent RPC message.
   109  	MessageEventTypeRecv                                // Indicates a received RPC message.
   110  )
   111  
   112  // MessageEvent represents an event describing a message sent or received on the network.
   113  type MessageEvent struct {
   114  	Time                 time.Time
   115  	EventType            MessageEventType
   116  	MessageID            int64
   117  	UncompressedByteSize int64
   118  	CompressedByteSize   int64
   119  }
   120  
   121  // Status is the status of a Span.
   122  type Status struct {
   123  	// Code is a status code.  Zero indicates success.
   124  	//
   125  	// If Code will be propagated to Google APIs, it ideally should be a value from
   126  	// https://github.com/googleapis/googleapis/blob/master/google/rpc/code.proto .
   127  	Code    int32
   128  	Message string
   129  }
   130  

View as plain text