package fog import ( "context" "fmt" guuid "github.com/google/uuid" ) type operationCtxKey struct{} // OperationFields provides a keysAndValues string array compatible interface for the Operation field in GCP, // for use in fmt and logr.Logger style logging. e.g., logr.Logger.WithValues(OperationField(id)...) func OperationFields(opID string) []interface{} { ret := make([]interface{}, 2) ret[0] = fmt.Sprintf("%sid", gcpOperationKey) ret[1] = opID return ret } // Adds operation ID to context func SetOperationContext(ctx context.Context) context.Context { c := context.WithValue(ctx, operationCtxKey{}, guuid.New().String()) return c } func OperationID(ctx context.Context) string { if o, ok := ctx.Value(operationCtxKey{}).(string); ok { return o } return "" }