corel

package
v1.2.29 Latest Latest
Warning

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

Go to latest
Published: May 30, 2023 License: MIT Imports: 13 Imported by: 0

README

COREL (Correlation in Distributed Logs)

Usages

There are multiple places to use corel for establishment of related logs in microservice architecture. but 2 of them are most important. One while making intranet service-to-service call and the other while pushing any message to kafka topic or rabbitmq exchange.

For Api Call
import "gitlab.com/dotpe/mindbenders/corel"
....
req, err := http.NewRequest("GET",url,nil)
if err != nil {
	return res, err
}
corel.AttachCorelToHttpFromCtx(ctx, req)

corel.AttachCorelToHttpFromCtx(ctx, req) is important while adding corel information as header for http call.

For Pushing to Topic
publisher side
import "gitlab.com/dotpe/mindbenders/corel"
...
func getProduceTaskRequest(ctx context.Context, data interface{}, topic string) (*ProduceTaskRequest, error) {
	corelId, _ := corel.GetCorelationId(ctx)
	reqData := ProduceTaskRequestData{
		Data: data,
		Correlation: corel.EncodeCorel(corelId.Child()),
	}

	reqDataBytes, err := json.Marshal(reqData)
	if err != nil {
		return  nil, errors.New("unable to create produce task request")
	}

	taskRequest := ProduceTaskRequest{
		ReqBytes: reqDataBytes,
		Topic: "topic.x.y.z",
	}
	return &taskRequest, nil
}
consumer side
import "gitlab.com/dotpe/mindbenders/corel"

...
var tmp struct {
	CoRelationId string  `json:"correlation"`
	Order producer.UserOrderKafkaMsg `json:"data"`
}
if  err := json.Unmarshal(raw, &tmp); err != nil {
	return err
}
oe.CoRelationId = corel.DecodeCorelationId(tmp.CoRelationId).Sibling()
oe.Order = &tmp.Order
return  nil

.............
ctx := corel.NewCorelCtxFromCorel(oe.CoRelationId)

Documentation

Index

Constants

View Source
const CtxCorelLocator corelstr = "corel"

Variables

This section is empty.

Functions

func AmqpLoader added in v1.2.22

func AmqpLoader(ctx context.Context, headers amqp.Table)

unloading of corel info from ctx and loading it in kafka header

func AmqpUnloader added in v1.2.22

func AmqpUnloader(ctx context.Context, headers amqp.Table) context.Context

This will be used to load corel from kafka message's header to context unloading of corel info from header and loading it in ctx

func AttachCorelToHttp added in v1.0.16

func AttachCorelToHttp(corelid *CoRelationId, req *http.Request)

func AttachCorelToHttpFromCtx added in v1.0.16

func AttachCorelToHttpFromCtx(ctx context.Context, req *http.Request)

func DecodeCorel added in v1.2.12

func DecodeCorel(str string, dst interface{}) error

func EncodeCorel added in v1.2.12

func EncodeCorel(corelId *CoRelationId) string

func HttpCorelLoader added in v1.2.14

func HttpCorelLoader(ctx context.Context, header http.Header)

* inside header it will write `Corel`="base64 of json"

func HttpCorelUnLoader added in v1.2.14

func HttpCorelUnLoader(ctx context.Context, header http.Header) context.Context

*The below Unloader will work with gin.Context only.

func KafkaCorelLoader added in v1.2.14

func KafkaCorelLoader(ctx context.Context, headers *[]kafka.Header)

unloading of corel info from ctx and loading it in kafka header

func KafkaCorelUnLoader added in v1.2.14

func KafkaCorelUnLoader(ctx context.Context, headers *[]kafka.Header) context.Context

This will be used to load corel from kafka message's header to context unloading of corel info from header and loading it in ctx

func NewCorelCtx added in v1.2.2

func NewCorelCtx(sessionId string) context.Context

This is used when the default context is used to define a new corel

func NewCorelCtxFromCorel added in v1.2.14

func NewCorelCtxFromCorel(corelid *CoRelationId) context.Context

func NewCorelCtxFromCtx added in v1.2.2

func NewCorelCtxFromCtx(ctx context.Context, sessionId string) context.Context

This is used to define a new corel on the context

func NewCorelCtxFromRequest added in v1.2.8

func NewCorelCtxFromRequest(ctx context.Context, sessionId, requestId string) context.Context

Any task consumer will call this method only

Types

type CoRelationId

type CoRelationId struct {
	RequestId string `json:"requestId" header:"request_id"`
	SessionId string `json:"sessionId" header:"session_id"`
	Auth      string `header:"Authorization"`
	JWT       *jwtinfo

	AppRequestId,
	RequestSource string
	// contains filtered or unexported fields
}

CoRelationId correlationData

func DecodeCorelationId added in v1.2.12

func DecodeCorelationId(encoded string) *CoRelationId

func GetCorelationId

func GetCorelationId(ctx context.Context) (corelid *CoRelationId, err error)

GetCorelationId ...

func (*CoRelationId) Child added in v1.2.13

func (corelid *CoRelationId) Child() *CoRelationId

func (*CoRelationId) Enc added in v1.2.14

func (corelid *CoRelationId) Enc() string

func (*CoRelationId) GetRequestId added in v1.2.12

func (corelid *CoRelationId) GetRequestId() string

func (*CoRelationId) GetSessionId added in v1.2.12

func (corelid *CoRelationId) GetSessionId() string

func (*CoRelationId) Sibling added in v1.2.13

func (corelid *CoRelationId) Sibling() *CoRelationId

Jump to

Keyboard shortcuts

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