tracehandler

package
v1.0.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 21, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// KeyTrace : 寫入ctx locals 的 key
	KeyTrace = "Trace"
	// KeySpanID : 寫入ctx locals 的 key
	KeySpanID = "SpanID"
	// KeyTraceTrue : 寫入ctx local s的 key
	KeyTraceTrue = "TraceTrue"
)
View Source
const XCloudTraceContext = "X-Cloud-Trace-Context"

XCloudTraceContext : https://cloud.google.com/trace/docs/setup

Variables

View Source
var ConfigDefault = Config{
	TraceHaderKey:    XCloudTraceContext,
	AllResAddTraceID: false,
}

Functions

func GetTraceKey

func GetTraceKey() string

func New

func New(config ...Config) fiber.Handler

New : 新增中間層用於處理 Cloud Trace

config 暫時無值

func Res

func Res(c *fiber.Ctx) error

Res : 回應追蹤碼

Types

type ClientSet

type ClientSet struct {
	SpanID    SpanID
	TraceTrue TraceTrue
}

ClientSet : 自訂轉發參數

type Config

type Config struct {
	TraceHaderKey    string
	AllResAddTraceID bool
}

Config : 暫時沒有可自訂項目

type SpanID

type SpanID = string

SpanID : is the decimal representation of the (unsigned) span ID. It should be randomly generated and unique in your trace. For subsequent requests, set SPAN_ID to the span ID of the parent request. See the description of TraceSpan (REST, RPC) for more information about nested traces.

type Trace

type Trace struct {
	TraceID   TraceID   `json:"TraceID"`
	SpanID    SpanID    `json:"SpanID"`
	TraceTrue TraceTrue `json:"TraceTrue"`
	Raw       string    `json:"raw"`
}

Trace : https://cloud.google.com/trace/docs/setup

func Conv

func Conv(rawStr string) (t Trace, status bool)

Conv : 從 header 上的 X-Cloud-Trace-Context 取值

curl "http://www.example.com" --header "X-Cloud-Trace-Context: 105445aa7843bc8bf206b12000100000/1;o=1"

func Get

func Get(c *fiber.Ctx) Trace

Get : 取得傳入 Trace 相關 code

func NewTrace

func NewTrace(c *fiber.Ctx) Trace

func (Trace) Conv

func (t Trace) Conv() (str string)

Conv : 將 GoogleCloudTrace 轉為string結構

"X-Cloud-Trace-Context: TRACE_ID/SPAN_ID;o=TRACE_TRUE"

func (Trace) FastHTTPHeader

func (t Trace) FastHTTPHeader(req *fasthttp.Request)

FastHTTPHeader : 設定 fasthttp 發出的 header

func (Trace) HTTPHeader

func (t Trace) HTTPHeader(req *http.Request)

HTTPHeader : 設定 http 發出的 header

type TraceID

type TraceID = string

TraceID : is a 32-character hexadecimal value representing a 128-bit number. It should be unique between your requests, unless you intentionally want to bundle the requests together. You can use UUIDs.

type TraceTrue

type TraceTrue = bool

TraceTrue : must be 1 to trace this request. Specify 0 to not trace the request.

Cloud Trace doesn't sample every request. For example, if you use Java and OpenCensus, then only 1 request out of every 10,000 is traced. If you are using App Engine, requests are sampled at a rate of 0.1 requests per second for each App Engine instance. If you use the Cloud Trace API, then you can configure customer rates. Some packages, such as the Java OpenCensus package, support configuring the sampling rate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL