Jaeger SDK is the code for start tracing the service's operation in distributed system
type JaegerConfig struct {
Host string `mapstructure:"host"`
Environment string `mapstructure:"env"`
ServiceName string `mapstructure:"service-name"`
}| name | description | example |
|---|---|---|
| Host | The host of the Jaeger in format http://hostname:port |
http://localhost:14268 |
| Environment | Environment of current service | local |
| ServiceName | The name of service | gateway |
Initialize by calling gosdk.SetupTracer
if err := gosdk.SetupTracer(*JaegerConfig, tracerName){
// handle error
}| name | description | example |
|---|---|---|
| JaegerConfig | Jaeger Configuration | |
| tracerName | name of the tracer | gateway |
Start to trace
newCtx, span := gosdk.StartTracer(tracerName, spanName, ctx, opt...)
if span != nil {
defer span.End()
}| name | description | example |
|---|---|---|
| tracerName | name of tracer | verify-ticket-handler |
| spanName | name of span | verify-ticket |
| ctx | context to pass to another service with span | |
| opt | span start option (optional) |
| name | description | example |
|---|---|---|
| newCtx | context from tracer | |
| span | interface of span in tracer |
Utils function is the function that can be use in a various scenario
the function use for convert bool to *bool
boolPtr := gosdk.BoolAdr(boolean)| name | description | example |
|---|---|---|
| boolean | the boolean value | true |
| name | description | example |
|---|---|---|
| boolPtr | the boolean pointer |
the function use for convert string to *string
stringPtr := gosdk.StringAdr(string)| name | description | example |
|---|---|---|
| string | the string value | "hello world" |
| name | description | example |
|---|---|---|
| stringPtr | the string pointer |
the function use for convert int to *int
intPtr := gosdk.IntAdr(int)| name | description | example |
|---|---|---|
| int | the int value | 999 |
| name | description | example |
|---|---|---|
| intPtr | the int pointer |
the function use for convert uuid.UUID to *uuid.UUID
uuidPtr := gosdk.UUIDAdr(uuid)| name | description | example |
|---|---|---|
| uuid | the uuid value |
| name | description | example |
|---|---|---|
| uuidPtr | the uuid pointer |
the function use to get the current time pointer
currentTimePtr := gosdk.GetCurrentTimePtr()| name | description | example |
|---|---|---|
| currentTimePtr | current time pointer in *time.Time |
the function use to get the 2 last digit of current year
year2Digit := gosdk.GetCurrentYear2Digit()| name | description | example |
|---|---|---|
| year2Digit | current year in 2 last digit int |
66 |
the function use to get the current year of student from the student id
year, err := gosdk.CalYearFromID(studentID)
if err != nil{
// handle error
}| name | description | example |
|---|---|---|
| studentID | the student id | 633xxxxx21 |
| name | description | example |
|---|---|---|
| year | the year from student id | 3 |
Check is the variable existed in map
if ok := gosdk.IsExisted(map, key); !ok {
// handle error
}| name | description | example |
|---|---|---|
| map | the map structure | |
| key | the key of map that you want to check | "hello" |
| name | description | example |
|---|---|---|
| ok | boolean is existed | true |
merge slices of string into one slice
resultSlice := gosdk.MergeStringSlice(slice1, slice2, ...)| name | description | example |
|---|---|---|
| slice | the string slice |
| name | description | example |
|---|---|---|
| resultSlice | the slice of string that was merged | true |
Trim the string if existed in list
result := gosdk.TrimInList(word, sep, trimList)| name | description | example |
|---|---|---|
| word | the input word | /v1/path |
| sep | the separate work | / |
| trimList | the list of word that want to trim in map[string]struct |
map[string]struct{}{"v1": {}} |
| name | description | example |
|---|---|---|
| result | result string that was trimmed | /path |